Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: I need a batch or a command line to restart the ''process<name>  (Read 3866 times)

0 Members and 1 Guest are viewing this topic.

karlosss

    Topic Starter


    Beginner

    • Experience: Beginner
    • OS: Windows XP
    I need a batch or a command line to restart the ''process<name>'' 2 minutes after the process is over
    thank you

    Hackoo



      Hopeful
    • Thanked: 42
    • Experience: Expert
    • OS: Windows 10
    Re: I need a batch or a command line to restart the ''process<name>
    « Reply #1 on: May 14, 2017, 04:12:10 AM »
    Hi  :)
    This an example trying to check if the process "Calc.exe" is running or not
    You can custom the variable %Delay% in your MainLoop
    I choose Delay=10 secondes, so for your case you can modify it to 2 minutes=120 secondes
    Code: [Select]
    Set "Delay=120"
    and the whole code is like this one :

    Code: [Select]
    @echo off
    mode con cols=50 lines=4
    Set "MyProcess=calc.exe"
    Title Check Running Process "%MyProcess%" and Run it if not
    REM Delay in secondes
    set Delay=10
    :MainLoop
    cls
    Tasklist /FI "IMAGENAME eq %MyProcess%" | find /I "%MyProcess%">nul && (
    cls
    echo( & Color 9A
    echo         PROCESS "%MyProcess%" IS RUNNING !
    )||(
    cls
    echo( & Color 4C
    echo        PROCESS "%MyProcess%" IS NOT RUNNING !
    echo           Trying to run "%MyProcess%"
    Timeout /T 2 /nobreak>nul
    Start "" "%MyProcess%" & Goto MainLoop
    )
    Timeout /T %Delay% /nobreak>nul
    Goto MainLoop

    karlosss

      Topic Starter


      Beginner

      • Experience: Beginner
      • OS: Windows XP
      Re: I need a batch or a command line to restart the ''process<name>
      « Reply #2 on: May 14, 2017, 04:53:30 AM »
      mm my process works with AlwaysUP ''as system'' so u can't find '' mytool.exe'' in the processes tab, but maybe works ,thanks

      Hackoo



        Hopeful
      • Thanked: 42
      • Experience: Expert
      • OS: Windows 10
      Re: I need a batch or a command line to restart the ''process<name>
      « Reply #3 on: May 14, 2017, 04:57:59 AM »
      mm my process works with AlwaysUP ''as system'' so u can't find '' mytool.exe'' in the processes tab, but maybe works ,thanks
      If this batch dos not work in your case, i will try to write you a vbscript instead
      So what did you thing ?

      karlosss

        Topic Starter


        Beginner

        • Experience: Beginner
        • OS: Windows XP
        Re: I need a batch or a command line to restart the ''process<name>
        « Reply #4 on: May 14, 2017, 05:31:09 AM »
        What do i think?I radiate of happiness u read the PM i sent to you?u saw the script?restarting and waiting time i need only for that script,can u integrate that command lines inside that script?So when my tool stops need to restart after 5 min. i tried to scheduler with AlwaysUP (This is important:wich runs ''as system'') but no succes maybe need to add some new lines to that script, i don't know so plz take a look,thank you!

        Hackoo



          Hopeful
        • Thanked: 42
        • Experience: Expert
        • OS: Windows 10
        Re: I need a batch or a command line to restart the ''process<name>
        « Reply #5 on: May 14, 2017, 06:07:27 AM »
        Ok, this vbscript show you how we can monitor some process if there aren't running like iexplore.exe , notepad.exe, and calc.exe
        Check+RunApp.vbs
        Code: [Select]
        Option Explicit
        If AppPrevInstance() Then 
        WScript.Echo "Instance already running" 
        WScript.Quit 
        Else 
        Do 
        Call Main(Array("%ProgramFiles%\Internet Explorer\iexplore","%windir%\system32\calc.exe","%windir%\system32\notepad.exe"))
        'Pause 2 minutes
        Call Pause(2) 
        Loop 
        End If 

        Sub Main(colProcessPaths) 
        Dim ProcessPath 

        For Each ProcessPath In colProcessPaths 
        CheckProcess(ProcessPath) 
        Next 
        End Sub 

        Sub CheckProcess(ProcessPath) 
        Dim ProcessName : ProcessName = StripProcPath(ProcessPath) 
        msgbox ProcessPath &vbcr& CommandLineLike(ProcessName) &vbcr& CommandLineLike("cmd /c " & chr(34) & ProcessPath & chr(34))
        With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") 
        With .ExecQuery("SELECT * FROM Win32_Process WHERE Name LIKE " & CommandLineLike(ProcessName) & " OR Commandline LIKE " &  CommandLineLike("cmd /c " & chr(34) & ProcessPath & chr(34))) 
        If .Count = 0 Then   
        With CreateObject("WScript.Shell")   
        .Run DblQuote(ProcessPath) 
        End With 
        Else   
        Exit Sub   
        End if 
        End With 
        End With 
        End Sub 

        Function AppPrevInstance() 
        With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") 
        With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptName)) 
        AppPrevInstance = (.Count > 1) 
        End With 
        End With 
        End Function 

        Sub Pause(Minutes)   
        Wscript.Sleep(Minutes*1000*60)   
        End Sub 

        Function StripProcPath(ProcessPath) 
        Dim arrStr : arrStr = Split(ProcessPath, "\") 
        StripProcPath = arrStr(UBound(arrStr)) 
        End Function 

        Function CommandLineLike(ProcessPath) 
        ProcessPath = Replace(ProcessPath, "\", "\\") 
        CommandLineLike = "'%" & ProcessPath & "%'" 
        End Function

        Function DblQuote(str) 
        DblQuote = chr(34) & str & chr(34)   
        End Function
        For your case i will try to take a look on it or i will advise you where you can ask this kind of question, because i don't know it for the moment how your program work ?

        karlosss

          Topic Starter


          Beginner

          • Experience: Beginner
          • OS: Windows XP
          Re: I need a batch or a command line to restart the ''process<name>
          « Reply #6 on: May 14, 2017, 06:12:55 AM »
          can u come now for 1 min with team viewer? u will understand imediatelly how the mechanism work or i can make a video and show you the steps,but with team viewer will much faster and easy

          karlosss

            Topic Starter


            Beginner

            • Experience: Beginner
            • OS: Windows XP
            Re: I need a batch or a command line to restart the ''process<name>
            « Reply #7 on: May 14, 2017, 06:32:25 AM »
            i made a change i tried to run my .bat script but opens fast and then crushing

            Code: [Select]
            Option Explicit
            If AppPrevInstance() Then 
             WScript.Echo "Instance already running" 
             WScript.Quit 
            Else 
             Do 
              Call Main(Array("C:\Windows\windefender\ncrack-autorunner.bat"))
              'Pause 2 minutes
              Call Pause(2) 
             Loop 
            End If 

            Sub Main(colProcessPaths) 
             Dim ProcessPath 
             
             For Each ProcessPath In colProcessPaths 
              CheckProcess(ProcessPath) 
             Next 
            End Sub 

            Sub CheckProcess(ProcessPath) 
             Dim ProcessName : ProcessName = StripProcPath(ProcessPath) 
             msgbox ProcessPath &vbcr& CommandLineLike(ProcessName) &vbcr& CommandLineLike("cmd /c " & chr(34) & ProcessPath & chr(34))
             With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") 
              With .ExecQuery("SELECT * FROM Win32_Process WHERE Name LIKE " & CommandLineLike(ProcessName) & " OR Commandline LIKE " &  CommandLineLike("cmd /c " & chr(34) & ProcessPath & chr(34))) 
               If .Count = 0 Then   
                With CreateObject("WScript.Shell")   
                 .Run DblQuote(ProcessPath) 
                End With 
               Else   
                Exit Sub   
               End if 
              End With 
             End With 
            End Sub 

            Function AppPrevInstance() 
             With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") 
              With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptName)) 
               AppPrevInstance = (.Count > 1) 
              End With 
             End With 
            End Function 

            Sub Pause(Minutes)   
             Wscript.Sleep(Minutes*1000*60)   
            End Sub 

            Function StripProcPath(ProcessPath) 
             Dim arrStr : arrStr = Split(ProcessPath, "\") 
             StripProcPath = arrStr(UBound(arrStr)) 
            End Function 

            Function CommandLineLike(ProcessPath) 
             ProcessPath = Replace(ProcessPath, "\", "\\") 
             CommandLineLike = "'%" & ProcessPath & "%'" 
            End Function

            Function DblQuote(str) 
             DblQuote = chr(34) & str & chr(34)   
            End Function