So I am using PsExec to run remote scripts, packages and programs on certain workgroup computers.

I implemented it simply this way:

vb Code:
  1. psexecprocess.Start()
  2.                                                          psexecprocess.WaitForExit()
  3.                                                          Dim exitcode As Integer = psexecprocess.ExitCode
  4.                                                          If Not exitcode = 0 Then
  5.                                                              sbU("PsExec returned exit code: " & exitcode, red, Corp)
  6.                                                              If exitcode = 5 Then
  7.                                                                  sbU("[ " & UserName & " ] doesn't have admin privilages, cannot execute PsExec", red, Corp)
  8.                                                              End If
  9.                                                          Else
  10.                                                              sbU("Finished remotely copying and executing CCleaner package", blue)
  11.                                                          End If

sbU is just a function that updates a status bar and writes to a log.

So 5 is an easy one I implemented (the account used does not have remote admin privilages). Everything should be 0 if it's fine so I go else... BUT... it keeps churning out random junk exit codes.

PCAnywhere does it, a deployment script/package for installing/executing portable Teamviewer does it, A script I wrote to run extended cleanmgr (disk cleaner) does it, everything seems to do it.

I am using the method to connect by adding network share $IPC then using psexec commandlines (not passing user/pass directly through psexec -- after reading some security forensics on psexec). This shouldn't matter at all, everything connects and runs fine.

Essentially lets say I run my Extended CleanmGR VBScript it's:

[highlight =vb]psexecprocess.StartInfo.Arguments = "\\" & remoteIP & " -s -i -d /accepteula wscript.exe /nologo C:\SWSetup\CleanerMGR\CleanMGR.vbs"
[/highlight]

The script detects OS, adds the proper registry entries (to preselect extended cleanmgr options) and shell.exec cleanmgr.exe /sagerun (from within the script)