Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need script to run exe for 30 seconds and then close 1

Status
Not open for further replies.

hydruid

Programmer
Feb 5, 2008
103
US
I have been googling this for hours and haven't found anything yet, I'm going to keep looking though

I want a vb script to run an executable file (.exe) for 30 seconds and then close automatically.

Any suggestions would be great!
 
you can try this

Code:
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run "Path to Exe file"
sleep(30000)
Set colProcessList = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Process WHERE Name = '<name of exe>'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next

 
Note the .exe file and script need to be running on the same machine.
 
thank you sooo much for your quick response.

I need to run the executable over a unc path

\\fs01\programs$\app.exe

 
I used your script, and took out 2 lines, to test closing the application and it worked! Just now need to tweak it to run that application over a unc path

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set wshShell = WScript.CreateObject ("WSCript.shell")

Set colProcessList = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process WHERE Name = 'App.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
 
Ok i got it working. I had to correct the sleep section. Also instead of using a unc path, I used a map drive. Here is the script:

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run "r:\app.exe"
WScript.Sleep(40000)
Set colProcessList = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process WHERE Name = 'app.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
 
A great way of thinking people is to click on the " Thank JohnDoe for this valuable post!" link you'll see in each reply.
:)

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top