Page 1 of 2 12>
Topic Options
#105732 - 2003-10-10 12:35 AM RunAs
Richie19Rich77 Offline
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
#105733 - 2003-10-10 01:09 AM Re: RunAs
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
nice!
no more tcqRunAs!
ja!!!!

and,btw...
this link is for the text ( I want to see what I DL):
http://www.anbsoftware.co.uk/netadmin/runas/download.php

weirdly though, they list it as 1.0 still.
_________________________
!

download KiXnet

Top
#105734 - 2003-10-10 09:57 AM Re: RunAs
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Yeah I forgot to post the ANB Software web page, the RunAs download on thier site is an old version with a username bug.

They E-Mailed me the latest version which I am hosting on my FTP server.

Just download the one off their website and it looks like they have just updated it.

So either download will be fine.

[ 10. October 2003, 09:59: Message edited by: Richard Farthing ]

Top
#105735 - 2003-10-10 02:48 PM Re: RunAs
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Ja, they did not update the version information on the file either. Bad form.
Top
#105736 - 2003-10-10 04:49 PM Re: RunAs
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Great news...However I am still getting an error '267 - The directory name is invalid'...Anyone else experience this? I am typing...

runas.exe /user:DOMAIN\User /pass:Password %windir%\notepad.exe

Top
#105737 - 2003-10-10 04:50 PM Re: RunAs
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Nevermind...Figured it out.
Top
#105738 - 2003-10-10 05:54 PM Re: RunAs
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
The start-up directory must be local, so do a 'CD "c:\"'.

If not and the start-up dir is set to network, you will recieve a 267 error.

Top
#105739 - 2003-10-10 05:55 PM Re: RunAs
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Please post what was wrong so others may learn from your experience.
Top
#105740 - 2003-11-04 12:22 AM Re: RunAs
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Sorry...I must have missed the responses. If I recall correctly...It was something to do with having the full path before the runas.exe. Some stupid mistake on my part.
Top
#105741 - 2003-11-05 10:35 AM Re: RunAs
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
For clarification (in case anyone dredges this up with the search engine) the problem is prevalent with just about all the SU/RunAs commands.

When you call the command from a UNC path during login or a similar process the command objects to not running in a valid local directory. This can also happen when the current directory becomes invalid due to the change in credentials (permissions)

The simple solution is to change to a local drive and directory which is valid for both the old and new credentials before calling the command.

Top
#105742 - 2003-11-05 11:20 AM Re: RunAs
barkingstars Offline
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
#105743 - 2003-11-05 11:35 AM Re: RunAs
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
You should really have opend up a new post rather then using an existing post.

Is the password that your using for account MR-3211\administrator.

this will be the local account on the workstation, that the RunAs is being run at, if you want to use a domain account you need to put in /user:{Domain}\Administrator.

The @Error will get the error status of the Shell reference, and that has run fine, so you will get a Error 0.

Top
#105744 - 2003-11-06 12:24 AM Re: RunAs
barkingstars Offline
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 Offline
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 Offline
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
#105747 - 2003-11-07 12:17 AM Re: RunAs
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
quote:

shell '.\runas /user:administrator /pass:HIDDEN /w nonexistent.exe'
? @ERROR " " @SERROR

Won’t this just return the error code of the shell command?? So error code 0 is actually correct behavior?

Runas runs in shell so error code is in shell and not in kix because kix does not fire runas but shell does. Kix just fires shell and moves on. What shell runs is irrelevant to kix if shell is started correctly.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#105748 - 2003-11-07 02:44 AM Re: RunAs
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
nope.
shell is kixtart command.
shell is a command that does return error-value of the proggy that is being shell'ed.
_________________________
!

download KiXnet

Top
#105749 - 2003-11-07 04:55 AM Re: RunAs
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
However, the main problem is still that it exposes the password.
_________________________
There are two types of vessels, submarines and targets.

Top
#105750 - 2003-11-07 01:36 PM Re: RunAs
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Jens, it's no problem, it's a CHALLENGE... [Razz]
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#105751 - 2003-11-07 04:57 PM Re: RunAs
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Nope, problems, as it already has published solutions [Wink]

[ 11. November 2003, 04:24: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.14 seconds in which 0.092 seconds were spent on a total of 13 queries. Zlib compression enabled.

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