1.

Solve : I need a batch or a command line to restart the ''process?

Answer»

I need a batch or a command line to restart the ''process'' 2 minutes after the process is over
thank youHi 
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 MainLoopmm my process works with AlwaysUP ''as system'' so u can't find '' mytool.exe'' in the processes tab, but maybe works ,thanks Quote from: karlosss 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
If this batch dos not work in your case, i will try to write you a vbscript instead
So what did you thing ?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!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 FunctionFor 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 ?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 easyi 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


Discussion

No Comment Found