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

Taskkill wscript.exe

Status
Not open for further replies.

EdRev

Programmer
Aug 29, 2000
510
0
0
US
I have multiple instance of WSCRIPT.exe running on our server under SYSTEM user.
I need to kill these processes using TaskKill.
Will this kill all the instances/processes?

strProcess = "WScript.exe"
Set oShell= CreateObject("WScript.Shell")
oShell.Run "TaskKill /s /im " & strProcess & " /f", WindowStyle, WaitOnReturn
Set oShell = Nothing

Also, what will happen if I do not have an instance of wscript.exe and I run the above script?
 
To kill it, you need to have the same userid as the user who started the job. This gets difficult if it is LocalUser. Even admins cannot kill LocalUser. You may or may not be able to kill the System user processes. It is all to do with privileges and special users.

There are several vb kill programs floating around but they don't all work in every situation. Maybe this thread from 3 years back might help
Basically what you need to do is switch the ACL of the task you wish to kill to your own id or temporarily fake being the owner of the pid. Some kills do it one way, others do it the other way. I've had lots of problems with remote scripts started by terminal servers. The number of different techniques you have to deploy is enough to frustrate anyone.
 
In short...take a look at WMI and Win32_Process...

Code:
Option Explicit

Dim strComputer : strComputer = "."
Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & _
						strComputer & "\root\cimv2")
Dim colProcesses : Set colProcesses = objWMIService.ExecQuery(_
				  "Select * From Win32_Process Where Name = 'wscript.exe'")
Dim objProcess, strUserName, strDomain, strCommandLine
For Each objProcess In colProcesses
	On Error Resume Next
	' CommandLine is valid for WinXP and greater
	strCommandLine = objProcess.CommandLine
	objProcess.GetOwner strUserName, strDomain
	WScript.Echo strCommandLine
	WScript.Echo strDomain & "\" & strUserName
	WScript.Echo ""
	strCommandLine = "" : strUserName = "" : strDomain = ""
' 	objProcess.Terminate() ' to kill process
	On Error GoTo 0
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top