#148173 - 2005-09-21 10:14 AM
get Errorlevel
|
Maik
Getting the hang of it
Registered: 2003-01-14
Posts: 87
|
Hello, I want to catch the errorlevel of psexec or the "net localgroup" and pipe it into a textfile. What is wrong with my code?
Code:
If $ClientAdmins.IsMember('WinNT://Domain/Admins') <> 1
Shell "psexec.exe \\192.168.2.10 -u @domain\Admin -p Password -i" + " cmd /c net localgroup Administrator " + chr(34) + "Domain\Admins" + chr(34) + " /add" $Errorcode = @ERROR + ", " + @SERROR If (RedirectOutput("%TEMP%\@WKSTA.log", 1)) = 0 'Errorcode: $Errorcode' EndIf
EndIf
Maik
|
|
Top
|
|
|
|
#148175 - 2005-09-21 10:54 AM
Re: get Errorlevel
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
What is wrong with my code?
@ERROR is a number, so when you use "+" KiXtart will coerce the rest of the line to a numeric type as well.
You need to convert @ERROR to a string first. You can do this either explicitly by using CStr(), or implicitly by starting the expression with a string.
Easiest is something like: Code:
$Errorcode = "["+@ERROR+"] "+@SERROR
|
|
Top
|
|
|
|
#148176 - 2005-09-21 10:58 AM
Re: get Errorlevel
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
If shell is started ok then @error will be 0 cause kix did what it had to do (launch Shell) and no errors came up. To get the error codes of a Shell you could use the WSHPipe() UDF.
WshPipe() - Pipes the results of a shell command to an array.
That's not quite correct. If PSEXEC launches, completes and returns an error code (ERRORLEVEL) then @ERROR will be set to the error code.
If you use "RUN" or if the process you start detaches from the controlling process then @ERROR will always be zero as long as the process starts ok.
|
|
Top
|
|
|
|
#148178 - 2005-09-21 01:19 PM
Re: get Errorlevel
|
Maik
Getting the hang of it
Registered: 2003-01-14
Posts: 87
|
Hello,
can I get the Errorlevel of "net localgroup" also?
Maik
|
|
Top
|
|
|
|
#148180 - 2005-09-21 01:43 PM
Re: get Errorlevel
|
Maik
Getting the hang of it
Registered: 2003-01-14
Posts: 87
|
How?
|
|
Top
|
|
|
|
#148183 - 2005-09-21 04:29 PM
Re: get Errorlevel
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
It shouldn't be an issue.
From a Windows IT Pro article
Quote:
Whenever a process executed with PsExec is completed, PsExec displays the process's exit code and returns the exit code as its own exit code
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 756 anonymous users online.
|
|
|