#105732 - 2003-10-10 12:35 AM
RunAs
|
Richie19Rich77
Seasoned Scripter
   
Registered: 2002-08-16
Posts: 624
Loc: London, England
|
A working version of RunAs supplied by ANB Software. Download RunAs
All the bugs have now been sorted, and seems to be working fine.
I will be posting a new version of KiXRunAs soon, with much more functions.
quote: RUNAS USAGE:
RUNAS [/profile] [/env] [/netonly] [/s] /user:<UserName> [/pass:<Password>] program
/profile if the user's profile needs to be loaded.Default /env to use current environment instead of user's /netonly use if the credentials specified are for remote access only /s run this program silently with no prompts or displays /w wait for program to finish /user <UserName> should be in form of USER@DOMAIN or DOMAIN\USER /pass <Password> should be the password of the user program command line for EXE. See below for examples
Examples: > runas /profile /user:mymachine\administrator cmd > runas /env /user:user@domain.anbsoftware.com notepad \"my file.txt\"
NOTE: Enter user's password if prompted NOTE: When using /s you must specify the password on command line
|
Top
|
|
|
|
#105742 - 2003-11-05 11:20 AM
Re: RunAs
|
barkingstars
Fresh Scripter
Registered: 2003-01-22
Posts: 11
|
I've been testing this out and it's clearly very useful.
One problem I'm having though is that I don't seem to be able to get it to return an error code back to the script. Does anyone know a way around this?
Example:
code:
shell '.\runas /user:administrator /pass:incorrectpassword /w cmd' ? @ERROR " " @SERROR
returns:
code:
Attempting to start "cmd" as user "MR-3211\administrator"... RUNAS ERROR: Unable to run 1326 - Logon failure: unknown user name or bad password.
0 The operation completed successfully.
|
Top
|
|
|
|
#105744 - 2003-11-06 12:24 AM
Re: RunAs
|
barkingstars
Fresh Scripter
Registered: 2003-01-22
Posts: 11
|
You seem to misunderstand. I'm using an incorrect password on purpose to see if runas returns the error code. As you can see in the output it returns an error to the stdout but does not return that error to Kix.
I want to use Runas in a script I'm writing and I'd like to stop execution of the script if it fails to login correctly. As it stands there appears (unless anyone knows a way) no simple way of doing this.
In addition, here's another test I tried this time trying to run an executable that doesn't exist: Example
code:
shell '.\runas /user:administrator /pass:HIDDEN /w nonexistent.exe' ? @ERROR " " @SERROR
Output:
code:
Attempting to start "nonexistent.exe" as user "MR-3211\administrator"... RUNAS ERROR: Unable to run 2 - The system cannot find the file specified.
0 The operation completed successfully.
As you can see, there is still on error returned. [ 05. November 2003, 12:32: Message edited by: barkingstars ]
|
Top
|
|
|
|
#105745 - 2003-11-05 02:01 PM
Re: RunAs
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Hmm. Using standard "runas", %ERRORLEVEL% is set to "1" on a login failure.
Here is a simple work-around to test if the login is likely to work:
code:
$sStatusFile='C:\TEMP\RunAs_OK.txt' $sUser='DOMAIN\username' $sPass='Secret' ; Remove previous run failures If Exists($sStatusFile) Del $sStatusFile EndIf Shell '.\runas /user:'+$sUser+' /pass:'+$sPass+' %COMSPEC% /C echo Success >'+$sStatusFile If @ERROR OR %ERRORLEVEL% "ErrorLevel="+%ERRORLEVEL%+", Error="+@ERROR+" "+@SERROR Exit @ERROR | %ERRORLEVEL% EndIf If Exists($sStatusFile) Del $sStatusFile "Runas Succeeded."+@CRLF Else "Runas failed. Error unknown"+@CRLF EndIf
The temporary file will not be created if the login fails, so you can use this as a test.
Even better if you can create this sort of sentinel file in the actial process that you are launching.
|
Top
|
|
|
|
#105746 - 2003-11-06 11:58 PM
Re: RunAs
|
It_took_my_meds
Hey THIS is FUN
   
Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
|
Hi All, I wrote a function to implement the new runas tool. Cheers, Richard
code:
;---------------------------------------------------------------------------------------------------- RunAs ;FUNCTION RunAs($CommandType,$Command,OPTIONAL $Switches) ;ACTION Runs installations as administrator ;SYNTAX RETCODE = RunAs($CommandType,$Command[,$Switches]) ;PARAMETERS COMMANDTYPE ; Either SHELL or RUN depending on whether the script waits for the program or not ; COMMAND ; The command to run ; SWITCHES ; Optional switches for the runas.exe. ; /profile if the user's profile needs to be loaded.Default ; /env to Use current environment instead of user's ; /netonly Use If the credentials specified are For remote access only ;RETURN 0 if successful, otherwise error code ;REMARKS none ;DEPENDENCIES none ;EXAMPLE $=RunAs("Run",$Exepath+"\EPO\FramePkg.exe")
Function RunAs($CommandType,$Command,OPTIONAL $Switches)
If InGroup(@WKSTA+"\"+SIDToName("S-1-5-32-544")) OR @INWIN=2 $RunAs=Execute($CommandType+" '"+$Command+"'") Else If $Switches<>"" $Switches=$Switches+" " EndIf If $CommandType="Shell" $Switches=$Switches+"/w " EndIf $RunAs=Execute($CommandType+" '"+$ExePath+"\Utils\Runas.exe /s "+$Switches+"/user:"+@WKSTA+"\Administrator /pass:"+$AdminPwd+' "'+$Command+'"'+"'") EndIf
EndFunction
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1574 anonymous users online.
|
|
|