Noob help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
digitalwaffles
Posts: 2
Joined: 31 Jan 2014 09:15

Noob help

#1 Post by digitalwaffles » 31 Jan 2014 09:21

What am I doing wrong here? I'm trying to run "program.exe" in an elevated command prompt, either by the localadmin or by domain account. Also, is it possible to run this as one file instead of two?

CLS
@ECHO OFF
ECHO Press 1 to login as local admin.
SET /P id=Enter ID: %=%
IF %id%==1 GOTO LOCALADMIN
ELSE GOTO USER
:LOCALADMIN
RUNAS /USER:%COMPUTERNAME%\Administrator program.exe
:USER
RUNAS /USER:DOMAIN\%id% program.exe

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Noob help

#2 Post by Squashman » 31 Jan 2014 10:01

Code: Select all

@ECHO OFF
cls
ECHO Press 1 to login as local admin.
SET /P id=Enter ID:
IF %id%==1 (
   RUNAS /USER:%COMPUTERNAME%\Administrator program.exe
) else (
   RUNAS /USER:DOMAIN\%id% program.exe
)

digitalwaffles
Posts: 2
Joined: 31 Jan 2014 09:15

Re: Noob help

#3 Post by digitalwaffles » 31 Jan 2014 10:51

Thank you! Do you know if there is any way to run this from a network drive? It seems I can only run it locally. Also, is there any way to make it as one file instead of having two?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Noob help

#4 Post by Squashman » 31 Jan 2014 13:52

digitalwaffles wrote:Thank you! Do you know if there is any way to run this from a network drive? It seems I can only run it locally.

Have no idea. The majority of my batch files sit out on a network drive and run just fine.
digitalwaffles wrote:Also, is there any way to make it as one file instead of having two?

Not sure what you mean. It is one batch file. Why are you saying it is two?

booga73
Posts: 108
Joined: 30 Nov 2011 16:16

Re: Noob help

#5 Post by booga73 » 31 Jan 2014 21:43

Hi,

I'm only borrowing for illustration purposes what Squashman wrote; good line of code too :)

@ECHO OFF
cls
ECHO Press 1 to login as local admin.
SET /P id=Enter ID:
IF %id%==1 (
RUNAS /USER:%COMPUTERNAME%\Administrator program.exe
) else (
RUNAS /USER:DOMAIN\%id% program.exe
)


now, if you want to launch from a network share, i.e. by placing this batch script on a network share, you can modify the script which Squashman wrote .. .

@ECHO OFF
cls
ECHO Press 1 to login as local admin.
SET /P id=Enter ID:
IF %id%==1 (
RUNAS /USER:%COMPUTERNAME%\Administrator c:\program files\program.exe
) else (
RUNAS /USER:DOMAIN\%id% c:\program files\program.exe
)
[/code]

c:\program files\program.exe is the actual path on the immediate local computer that has whatever program that is installed.

Now, for Pressing 1, if 1 isn't pressed the default command execution would be:

Code: Select all

RUNAS /USER:DOMAIN\%id% c:\program files\program.exe


does that help simplify the matter?

v/r Booga73

Post Reply