1

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.

CristiFati
  • 38,250
  • 9
  • 50
  • 87
user3590266
  • 51
  • 1
  • 4
  • How do you run your script? [Here](http://stackoverflow.com/questions/14902134/cannot-use-parentheses-when-calling-a-sub-error-800a0414-vbs)'s an example of using `Call`. Have you tried `On Error Resume Next`? In many cases 255 means that the program actually wanted to return -1. – CristiFati Feb 09 '16 at 18:00
  • @CristiFati `On Error Resume` Next is already stated, but i want to stop the script if the command exit code is not 0. The way i call the command is `Set WshShell = CreateObject("WScript.Shell")` and then calling the command like i mentioned above. What means -1 ? – user3590266 Feb 10 '16 at 08:22
  • @bgalea Yes, and i will probably use WMI at the end, but, i want to understand why sometimes i got this error. – user3590266 Feb 10 '16 at 08:25

2 Answers2

0
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.

0

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.

hollopost
  • 569
  • 9
  • 28