Install as Administrator inside batch script

Posted on 2009-04-29
Medium Priority
Last Modified: 2013-11-10
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.
Question by:mhmservices

Expert Comment

ID: 24263186
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

LVL 11

Expert Comment

ID: 24267173
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.

Author Comment

ID: 24268458
An example would be helpful.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 24269664
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("wscript.shell")
'Define the command to run below
cmmd = "runas /user:administrator notepad.exe"
'Runs the command you entered above
Sh.run cmmd

Open in new window

LVL 11

Accepted Solution

darrenmcwi earned 2000 total points
ID: 24282403
/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.

Expert Comment

by:Mark Pavlak
ID: 24320227
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Make the most of your online learning experience.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Loops Section Overview

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question