Page 1 of 1 1
Topic Options
#148173 - 2005-09-21 10:14 AM get Errorlevel
Maik Offline
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
#148174 - 2005-09-21 10:38 AM Re: get Errorlevel
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
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.


Edited by Mart (2005-09-21 10:44 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#148175 - 2005-09-21 10:54 AM Re: get Errorlevel
Richard H. Administrator Offline
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 Offline
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
#148177 - 2005-09-21 12:10 PM Re: get Errorlevel
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Oops didn't see the psexec thingie.
My bad.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#148178 - 2005-09-21 01:19 PM Re: get Errorlevel
Maik Offline
Getting the hang of it

Registered: 2003-01-14
Posts: 87
Hello,

can I get the Errorlevel of "net localgroup" also?

Maik

Top
#148179 - 2005-09-21 01:42 PM Re: get Errorlevel
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Yep
_________________________



Top
#148180 - 2005-09-21 01:43 PM Re: get Errorlevel
Maik Offline
Getting the hang of it

Registered: 2003-01-14
Posts: 87
How?
Top
#148181 - 2005-09-21 02:15 PM Re: get Errorlevel
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Code:
shell '%ComSpec% /C net localgroup localgroupname username /add >nul'
"Errorlevel net localgroup: " @error



should do

[Edit: forget the above, just realize that you psexec it ]

M..maybe if you redirect the error stream to a file and then read that later on?

Code:

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 2>[path]error.txt"




then, open(), readline(), close()


Edited by Jochen (2005-09-21 02:48 PM)
_________________________



Top
#148182 - 2005-09-21 02:47 PM Re: get Errorlevel
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Psexec is a security risk.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#148183 - 2005-09-21 04:29 PM Re: get Errorlevel
Richard H. Administrator Offline
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
#148184 - 2005-09-21 04:37 PM Re: get Errorlevel
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Oh, so then ...
_________________________



Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.12 seconds in which 0.082 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org