How to run a VB Script that will execute an install using RUN AS administrator?

Posted on 2011-05-06
Last Modified: 2012-05-11

I am totally noob in terms of any scripting!

I need to initiate an EXE within a citrix published desktop environment when a users logs that will RUN AS administrator.  It needs to work the same way if you were going to right click the EXE and select RUN AS and enter credentials.

I thought I could setup a Group Policy to initiate the script at log-on but then i realize i know nothing about VB Script!  Is this difficult?

Filename:   123.exe
Question by:LenCepeda

    Author Comment

    I forgot to mention the most important part of the script.  

    When the installtion is executed, it will determine that the program is already installed and the user will be prompted to either REPAIR or REMOVE the application.  I need the REPAIR options selected.  Is this possible?
    LVL 32

    Accepted Solution

    dont believe so as the RUN AS problem arises requiring admin user interaction or storage of the password within the script/batch file.

    However, scripts that run as part of GPO "windows Startup" , run before user logs on and as the SYSTEM user. Hence have access to the entire system, but NOT to a users profile.

    I have a script that installs  dll's this way. (until 64bit dll caused issues). note that all source files must be either already on the local system or on the SYSVOL share so that the startup script has access

    'script to copy & install dsofile to each PC
    ' Constants for opening files
    Const OpenFileForReading = 1
    Const OpenFileForWriting = 2
    Const OpenFileForAppending = 8
    '--- set up files & log ---------
    const ScrFldr="\\thor\SYSVOL\\scripts\"       'std source location
    const LogFldr="\\thir\SYSVOL\\logs\"       
    	dim a, src , sVers
    	dim fs
    	lf = "installs.log"
    	Set oNet = CreateObject("WScript.Network")
    	datetime=Year(now()) & Right("0" & Month(now()), 2) & Right("0" & Day(now()), 2) & "=" & Right("0" & Hour(now()), 2) & Right("0" & Minute(now()), 2) '& Right("0" & Second(now()), 2)
    	Set fso = CreateObject("Scripting.FileSystemObject")  
    	sysfld = fso.GetSpecialFolder(1)    'the system folder
    	winfld =  fso.GetSpecialFolder(0)   'the windows folder
    	' write to Log 
    	Set flf = fso.GetFile(logfldr & lf)
    	Set tslf = flf.OpenAsTextStream(OpenFileForAppending)
    	tslf.Write (Onet.ComputerName & " , " & "BEGIN" & " , " & Datetime & vbCrLf)
    '------- end setup section ----
    '----copy dsofile if not exist --------------
    	If (fso.FileExists(winfld & "\" & src )) Then
        		msg = "dsofile exists."
    		sVers = fso.GetFileVersion(winfld & "\" & src )
    		msg = msg & " v=" & sVers
    	end if
    	'msgbox ("vers" & msg)
    	if left(sVers,6) = "2.1.28" then    
    		'no action needed      should be 2.1.2841
    		set f1 = fso.GetFile( scrfldr & src )
    		f1.Copy winfld & "\" & src,True
    		a=(sysfld & "\regsvr32.exe /S " & winfld & "\" & src )
    		CreateObject("Wscript.Shell").Run a
    		msg = msg & " Install dsofile "
    		'msgbox("dsofile done")
    	End If
    '--- write to log file -----
    	tslf.Write (Onet.ComputerName & " , " & msg & " , " & Datetime & vbCrLf)
    '------ end ---
    	set onet = nothing
    	Set FSO = Nothing

    Open in new window

    LVL 65

    Assisted Solution

    Hi there, if you put your username and password into the script, it should do the job as a logon script.

    There is the obvious security risk involved with elevating rights like this though.....a VBS is a plain text file.


    strEXE = "\\server\share\123.exe"
    strPSExec = "\\server\share\psexec.exe"
    strUser = "domain\administrator"
    strPassword = "Y0urP@ssw0rd"
    Set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objNetwork = CreateObject("WScript.Network")
    strEXE = objFSO.GetFile(strEXE).ShortPath
    strPSExec = objFSO.GetFile(strPSExec).ShortPath
    strCommand = strPSExec & " -accepteula -u " & strUser & " -p " & strPassword & " \\" & objNetwork.ComputerName & " " & strEXE & " /fa /qb"
    objShell.Run strCommand, 1, True

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
    Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    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

    11 Experts available now in Live!

    Get 1:1 Help Now