VBScript - Check If The Process Is Running And End It
Environment
It is for check if the process is running. If yes, close it. It is for upgrade the application
- Microsoft Windows XP
It is for check if the process is running. If yes, close it. It is for upgrade the application
'For run a command in shell
Set oShell = WScript.CreateObject("WScript.Shell")
'End the process
'The parameter should be like this "a,b,c", which is for splitting
'Param String sPro
Function endProcess(sPro)
pros = Split(sPro, ",")
taskKill = "taskkill /F"
For Each pro in pros
taskKill = taskKill & " /IM " & pro
Next
WScript.Echo taskKill
oShell.Run taskKill
End Function
'For check if the process is running
'Return boolean
Function isProcessRunning(pro)
Set colProcessList = GetObject("Winmgmts:").ExecQuery ("SELECT * FROM Win32_Process")
isProcessRunning = False
For Each objProcess in colProcessList
If objProcess.name = pro then
isProcessRunning = True
End if
Next
End Function
isRunning = isProcessRunning("test1.exe")
'Close the Lotus Notes if is running
If isRunning = True Then
endProcess("test1.exe,test2.exe")
End If