Programmatically launch an MSI under a different user account

I need a way of launching an MSI using an admin account through a VBscript.  Any help would be greatly appreciated.
tkelly45Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

?  That would be a good place to start.

-- Dan
0
tkelly45Author Commented:
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
               
Private Const LOGON32_LOGON_INTERACTIVE = 2
Private Const LOGON32_PROVIDER_DEFAULT = 0

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

lngLogonType = LOGON32_LOGON_INTERACTIVE
lngLogonProvider = LOGON32_PROVIDER_DEFAULT

blnResult = RevertToSelf()

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

Public Sub Logoff()
Dim blnResult As Boolean

blnResult = RevertToSelf()
End Sub




0
DanRollinsCommented:
Did you get that code from here:
    http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20222596.html

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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.