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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

770 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