问题
I'm trying to distribute software through SCCM 2012; running a simple command in a vbs, ends with the result code 255.
Example:
WshShell.run ("TASKKILL /F /IM """ & processname & """ /T", 0, True)
After returning 255, the script stops and doesn't install the software.
Someone had this problem? What does the code 255 mean?
Thanks.
回答1:
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")
For Each objItem in colItems
'msgbox objItem.ProcessID & " " & objItem.CommandLine
If objItem.name = "Calculator.exe" then objItem.terminate
Next
Is how to terminate programs in vbscript.
回答2:
this is the correct way
processname="my process name .exe"
WshShell.run "TASKKILL /F /IM """ & processname & """ /T", 0, False
wscript.sleep 300
First don't use parentheses
when you calling a Sub .Use parentheses when you assign that line
to Variable or when you use word call
.
var = WshShell.run ("TASKKILL /F /IM """ & processname & """ /T", 0, False)
Or
Call WshShell.run ("TASKKILL /F /IM """ & processname & """ /T", 0, False)
Second i prefer to use False
instead of True
to avoid relay in the script to wait until
finish execute the command line instead of that i like use wscript.sleep 300
if you will execute other line after this line of code .don't relay automatic stuff.
来源:https://stackoverflow.com/questions/35298200/taskkill-exit-code-255