/build/static/layout/Breadcrumb_cap_w.png

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 


3 Comments   [ + ] Show comments
  • You can use WScript.Sleep(10000) in your script to wait for 10 sec.
    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
    • rock_star: thanks for the help brother and the #2 link worked wonder. - talonsprem87 11 years ago
  • You should move the PopUp inside the loop. However, I would create a function with the process test and termination and call that inside a loop with a Yes/No/Cancel option. I would also add a test to make sure that the process did indeed get terminated, as many apps allow multiple instances to run. - anonymous_9363 11 years ago
    • Thanks for the solution VBScab. Wouldn't have bothered you'll, but this was the first time i got a bit stumped with vbscript. But i appreciate your response. Thank you ......all of you - talonsprem87 11 years ago
  • Could you post your final script, potentially with comments on the feedback shared? Would be useful to have that for others I'd think :) - drose23 11 years ago
    • set oshell=createobject("wscript.shell")
      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

Answers (0)

Be the first to answer this question

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ