Chcek for process and install the application
Hello
I have a requirement. I need to check if a process is running. If it does, prompt the user to close it. If the user doesnt close it in 10 seconds, force close it and continue with installation. So to tackle this, i used some reference and came up with following
Dim i
Dim strComputer,oShell,intReturn,oFSO,SysFolder
Dim FindProc
Const wshYes = 6
Const wshNo = 7
Const wshYesNoDialog = 4
Const wshQuestionMark = 32
strComputer = "."
Set oShell = CreateObject("Wscript.Shell")
Set oFSO=createObject("Scripting.FileSystemObject")
SysFolder=oshell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
'FindProc = inputbox("Enter process name","Information required")
FindProc="notepad.exe"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select Name from Win32_Process WHERE Name LIKE '" & FindProc & "%'")
If colProcessList.count>0 then
'wscript.echo FindProc & " is running"
intReturn = oShell.Popup("Notepad is running. Please close it and then click Yes",10, "Information",wshYesNoDialog + wshQuestionMark)
If intReturn=wshYes Then
oFSO.CreateFolder(SysFolder & "\Test")
Else
For Each objProcess in colProcessList
objProcess.Terminate()
Next
oFSO.CreateFolder(SysFolder & "\Test")
End If
else
wscript.echo FindProc & " is not running"
End if
Set objWMIService = Nothing
Set colProcessList = Nothing
Set oShell = Nothing
Now , those having a good hold on scripting will make it out at first instance. When user clicks yes, there is no way to check if the process is still running.
Would really appreciate if someone can help me out with this looping
Answers (0)
Be the first to answer this question
then terminate the process.
If you want to wait for process to get terminated and check again for its running status then then looping has to be done.
http://scriptingcenter.blogspot.in/2011/09/kill-multiple-instances-of-process.html
http://scriptingcenter.blogspot.in/2011/08/check-for-any-exe-running-and-waiting.html
let me know if you need more help/information - rock_star 11 years ago
strMessage="Close the notepad"
strTitle="Warning"
strComputer = "."
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
oreturn=oshell.popup("Do you want to start the installation",0,"Information",&H0 + &H40)
Do
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'notepad.exe'")
If colProcessList.Count>0 Then
ortn=oshell.popup(strMessage,0,strTitle,&H0 + &H40)
End If
Loop While colProcessList.Count>0
This is the final script i came up with. Hope this helps others too - talonsprem87 11 years ago