Install as Administrator inside batch script

Is it possible to install programs as a admin inside a batch script? I need to deploy some software but it requires admin rights which our users don't have.
Who is Participating?
/SAVECRED will survive reboots...atleast it does on my XP Pro 64 box.

jharrell2 is correct in thsat you can't directly send the password to RUNAS in the script. I've attached a VBScript that I pulled from Experts-Exchange that does pass the password be firing up a CMD windows and pushing the password to that. Not the most ellegant but it works.

I took a copy of this and modified it to include my admin user name and password and only take the command to run as an arguement. I then encrypted the VBScript with Microsoft's Script Encoder utility so the password would be hidden.  Using the script as attached from a shortcut would have exposed the password in the shortcuts properties although I'm sure you could just call that script from a parent script that you encrypt. Anyway, hack at it as you see fit.
I use Psexec to deploy things i can install via command line silently (i'll post one of my scripts).  If you do not want to remotely deploy or do not want the users to easily see the passwords, Google 'lsrunas' .  It encrypts the password.

The code below installs firefox remotely with psexec.
This may not be efficient but it works well.  I have 4 files + the firefox files.  
1)computer.txt ( populate this file with a list of computers (hostnames) seperated by a carriage return)

I basically copy all the files over and execute them on the remote machine (since i'm active directory, the creds i'm logged on as get passed)

If you're not AD and want the end users to do the installs themselves look into lsrunas.

hope this helps
File #2
REM filename remote_install.bat
c:\firefoxinstall\setup.exe /S
File #3
REM  filename: Run_me.bat
for /f "delims=," %%I IN (computer.txt) DO (
xcopy /e /f /h *.* \\%%I\c$\firefoxinstall\
psexec.exe \\%%I c:\firefoxinstall\remote_install.bat -w c:\

Open in new window

Core Windows has a RUNAS command that had an option to cache the password. You don't specify the password in the batch file, then the first time you run it, it prompts for it. Each additional time you run it, it won't prompt you any more as it's cached.

You can also use VBScript. The VBScript can then be encrypted with a free microsoft utility. Let me know if you need an example although I got my VBScript method for doing this from Experts Exchange so you might be able to search for it here.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

mhmservicesAuthor Commented:
An example would be helpful.
Beadvised, the /savecred switch of runas will not work on XP home.  And i'm pretty sure you'll have to enter those creds after reboots.  Also, as far as i know you cannot send the password in the script (with runas).  I've posted a vbs example below, but you will get a prompt for a password each time.

To encode your vbs look here:

the new file will change from .vbs to .vbe
'Following script passes command line using runas
option explicit
dim sh, cmmd, objshell
set sh = wscript.createobject("")
'Define the command to run below
cmmd = "runas /user:administrator notepad.exe"
'Runs the command you entered above cmmd

Open in new window

Mark PavlakCommented:
Danger will robinson,  Anything that is not complied is at risk, you never know who is nosey enough to look at a script or batch via notpad.  You can complie VBS scripts though, using that and sendkeys on a runas you can create the wrapper
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.