Install as Administrator inside batch script

Posted on 2009-04-29
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
    LVL 1

    Expert Comment

    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

    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

    An example would be helpful.
    LVL 1

    Expert Comment

    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

    LVL 11

    Accepted Solution

    /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.
    LVL 6

    Expert Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now