Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Programmatically launch an MSI under a different user account

Posted on 2003-03-21
Medium Priority
Last Modified: 2013-12-03
I need a way of launching an MSI using an admin account through a VBscript.  Any help would be greatly appreciated.
Question by:tkelly45
  • 2
LVL 49

Expert Comment

ID: 8193541
Have you tried using
    WShell.run "c:/somepath/SomeFile.MSI"

?  That would be a good place to start.

-- Dan

Author Comment

ID: 8194847
Running the script install isn't a problem it is running it under different security credentials that is the problem.   I need to run the install under an admin account but not all of our users have admin access to their desktop.

I have tried using the code below to logon as a different user.  I can successfully login as a different user under an admin account but it doesn't seem to work for a non-admin account.  blnResult returns false after LogonUser() with a non-admin account.

Option Explicit
Private Declare Function LogonUser Lib "advapi32.dll" _
Alias "LogonUserA" (ByVal lpszUsername As String, _
ByVal lpszDomain As String, ByVal lpszPassword As String, _
ByVal dwLogonType As Long, ByVal dwLogonProvider As Long, _
phToken As Long) As Long

Private Declare Function ImpersonateLoggedOnUser Lib "advapi32.dll" (ByVal hToken As Long) As Long
Private Declare Function RevertToSelf Lib "advapi32.dll" () As Long

Public Sub Logon(ByVal strAdminUser As String, ByVal _
                    strAdminPassword As String, ByVal strAdminDomain As String)
Dim lngTokenHandle As Long
Dim lngLogonType As Long
Dim lngLogonProvider As Long
Dim blnResult As Boolean


blnResult = RevertToSelf()

blnResult = LogonUser(strAdminUser, strAdminDomain, strAdminPassword, _
                                     lngLogonType, lngLogonProvider, _
blnResult = ImpersonateLoggedOnUser(lngTokenHandle)
End Sub

Public Sub Logoff()
Dim blnResult As Boolean

blnResult = RevertToSelf()
End Sub

LVL 49

Accepted Solution

DanRollins earned 360 total points
ID: 8197697
Did you get that code from here:

If so, then you will need to read down a little further.  The user who calls these functions must be enabled for the Permission setting of

     "Act as part of the operating system"

Admins have that, as do System Services which start as the LocalSystem login.

If you think about it, I'm sure that you will agree that it is a good idea to limit this sort of thing.  An MSI (or any other executable) could do nasty damage to a computer.  This safeguard is in place to prevent just any program started by any user from wiping out your system.  Thank goodness!

-- Dan

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

580 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