Option Explicit
Dim ws,MyApplication,MyProcess
Set ws = CreateObject("WScript.Shell")
MyApplication = "%Programfiles%\WinRAR\WinRAR.exe"
MyProcess = "WinRAR.exe"
Do
'We check if the process is not running so we execute it
If CheckProcess(MyProcess) = False then
Call Executer(DblQuote(MyApplication),0)'0 to Hide the console
'We made ••a one-minute break and continue in our loop to check
'whether or not our process exists(in our case = WinRAR.exe)
Pause(1)
End if
Loop
'***********************************************************************************************
Function CheckProcess(MyProcess)
Dim strComputer,objWMIService,colProcessList
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select Name from Win32_Process WHERE Name LIKE '" & MyProcess & "%'")
If colProcessList.count > 0 then
CheckProcess = MyProcess & " is running"
CheckProcess = True
else
CheckProcess = MyProcess & " is not running"
CheckProcess = False
End if
Set objWMIService = Nothing
Set colProcessList = Nothing
End Function
'***********************************************************************************************
Sub Pause(NMins)
Wscript.Sleep(NMins*1000*60)
End Sub
'***********************************************************************************************
Function Executer(StrCmd,Console)
Dim ws,MyCmd,Resultat
Set ws = CreateObject("wscript.Shell")
'La valeur 0 pour cacher la console MS-DOS
If Console = 0 Then
MyCmd = "CMD /C " & StrCmd & " "
Resultat = ws.run(MyCmd,Console,True)
If Resultat = 0 Then
Else
MsgBox "Une erreur inconnue est survenue !",16,"Une erreur inconnue est survenue !"
End If
End If
'La valeur 1 pour montrer la console MS-DOS
If Console = 1 Then
MyCmd = "CMD /K " & StrCmd & " "
Resultat = ws.run(MyCmd,Console,False)
If Resultat = 0 Then
Else
MsgBox "Une erreur inconnue est survenue !",16,"Une erreur inconnue est survenue !"
End If
End If
Executer = Resultat
End Function
'**********************************************************************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************