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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Terminate Service with VBScript

Status
Not open for further replies.

MaxGeek

Technical User
Jan 8, 2004
52
US
Hi I'm trying to make a VBScript that would terminate a windows service/application at a given time like set the script to do it every sunday.

However the script I'm using right now won't terminate the service/application I want, but it works at terminating other programs I've tried like calculator and etc.

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'OMNIS7.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next
 
What happens when you run this? Do you get an error?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
If i set it to notepad it closes the program. With it set to OMNIS7.exe (the program I want to close) I get nothing.

On thing though under task manager its not listed as a local service or network service. Rather its listed as System.
 
Do you have On Error Resume Next in your script? I suspect that you may. If you do, remove it and see what the error is.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
The vbscript I'm using is posted above, I don't think I have On Error Resume Nest.
 
When in task manager can you kill this process ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yeah I can kill it in task manager manually.
 
Just to be sure the name is correct:
For Each objProcess in colProcessList
WScript.Echo "'" & objProcess.Name & "'"
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
in this loop add some echo's, i think you should be able to return the result of .terminate method?

For Each objProcess in colProcessList
iResult = 0
Wscript.Echo objProcess.Name & " going to terminate"
iResult = objProcess.Terminate()
Wscript.Echo "return result = " & iResult
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top