Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

What is the code i can use in a vbs to run as administrator for an MSI installation.

Hi,

What is the code i can use in a vbs to run as administrator for an MSI installation.

What i mean is i have 2 MSI files that i need to install. Some machines fail to install as the logged in user does not have the permissions to install it failes. Can i use some script to run as administrator and install the MSI. I need to use this in a GPO.

REgards
Sharath
Avatar of zoofan
zoofan
Flag of United States of America image

bsarath I remeber last year writing code for you for vb6 app do you still have vb6?  if so I have app/code for a vb6 project that I created and use for what your trying to do.  I am still looking at the vbs angle but by using vb6 instead you will have a complied exe to do the same thing without clear text posting and admin account.

All the app does is start an installation process with 'runas' and an admin account(complied into code)

If you think you'd like to try it and you have vb6 still Ill post the code.


zf
Avatar of bsharath

ASKER

zoofan
Will i be able to achieve the same thing with an compiled exe.
Will logon scripts work with exe?
zoofan
Will i be able to achieve the same thing with an compiled exe.
Will logon scripts work with exe?
Yes


zf
ASKER CERTIFIED SOLUTION
Avatar of zoofan
zoofan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This should satisfy all your other open 'running msi with permission x' in a script questions as well.

if you need help calling in your login script let me know.


zf
Can you give me the calling and waiting as well
As noted below

zf
'Call as
RunAppandWait myapp.exe
 
'Routine to add to login script
Sub RunAppandWait(strappName)
  Dim oShell
  Set oShell = WScript.CreateObject("WSCript.shell")
  oShell.run strappName, 1, true
  Set oShell = Nothing
end Sub

Open in new window

zoofan just getting to know this better.
Forst need to compile "ID: 22111375" code to a exe then the last code has to be a vbs file which i need to use as an  login script.?
 
So what happend is the vbs file will call the exe and the exe will run the msi file with the run as credentials in it.
Am i right
 
ummm lol huh?

Create your install package(EX: mypack.exe).

Modify the vb6 app with the command line required to execute that package (where ever it is/what ever it is) compile the executable. (EX: \\server\share\mypack.exe) complied into installmyPack.exe

Modify your exisiting login script adding the sub routine above

Add execute code to the login script

'RunAppandWait installmyPack.exe'

where ever in the script you wish the install to take place in order of processing.


zf
>>Modify your exisiting login script adding the sub routine above
Can you add that please...
>>'RunAppandWait installmyPack.exe'
Is this the command i need to use in the GPO
Sorry a little blurred from my end
well,


Two options:

add the code to an exisiting login script(if you want me to do that I need the script!!)

OR

Create a new vbscript and paste into it the code below save as installAPPs.vbs save it on a netowrk share that users have read access to.


in your GPO User configuration\Windows settings\Scripts\Logon and add the script you just created.


Im not really sure how else to explain this.........

zf

'**************************************************************************************
'Start New script
'Creating a New Login script copy and paste to new file installAPP.vbs
'**************************************************************************************
'---------------Start installAPP.vbs copy--------------------------
		 Option Explicit
		'Add a new line for each app to install
		 RunAppandWait myapp.exe
		 
		 Sub RunAppandWait(strappName)
		 	Dim oShell
		 	Set oShell = WScript.CreateObject("WSCript.shell")
		 		oShell.run strappName, 1, true
		 	Set oShell = Nothing
		 end Sub
'---------------End installAPP.vbs copy--------------------------
'Creating a New Login script copy and paste to new file installAPP.vbs
'**************************************************************************************
'END New Script
'**************************************************************************************
 
 
 
'**************************************************************************************
'Start Add to script
'Adding code to an exisiting login script assuming it is a vbscript.
'**************************************************************************************
'---------------Start add code to exisiting login script copy--------------------------
 
'Add one line for each app to install
'Paste into your current login script BEFORE the wscript.quit
		RunAppandWait myapp.exe
 
'Add this sub routine to your script somewhere outside another function or sub but within the script
		 Sub RunAppandWait(strappName)
		 	Dim oShell
		 	Set oShell = WScript.CreateObject("WSCript.shell")
		 		oShell.run strappName, 1, True
		 	Set oShell = Nothing
		 end Sub
'---------------End add code to exisiting login script copy--------------------------
'**************************************************************************************
'END Add to Script
'***********************************************************

Open in new window

zoofan thanks i got an idea.
Below is the login script that i use now

Dim installer
Dim pck1,pck2,RunMsi,strLogFile,strLogData
 
 
Const PATHTOMSI1 = "\\sharathr-pc\Word\Templates.msi" '<--------------change to the path and name of MSI package 1 with install command line options
Const MYMSIPCK1 = "{F9949507-61C3-41F7-95A0-62BB}"'<-----------change to the App ID 1 from the excel worksheet copy and paste from open "{" to close "}" removing any spaces before and after
Const PATHTOMSI2 = "\\sharathr-pc\word\Template.msi" '<--------------change to the path and name of MSI package 2 with install command line options
Const MYMSIPCK2 = "{104D2D2A-6549-4002-882F-C9FE}"'<-----------change to the App ID 2 from the excel worksheet copy and paste from open "{" to close "}" removing any spaces before and after
strLogFile = "\\ServerName\Foldername\log1.csv" '<-------------------------------------------change to path/name of log file
 
 
Set installer = Wscript.CreateObject("WindowsInstaller.Installer")
Set products = installer.Products
pck1 = False
pck2 = False
        For Each product In products
                Select Case product              
                        Case MYMSIPCK1
                                pck1 = True
                        Case MYMSIPCK2
                                pck2 = True
                        End Select
        Next    
 Set oShell = WScript.CreateObject("WSCript.shell")       
        If pck1 = false Then
                RunMsi = "MSIEXEC /i " & PATHTOMSI1 & " /qb" '<-------changes to msi command line options can be done here
              oShell.run RunMsi,1,True
              If Err.Number = 0 Then 
              	strLogData = Now() & ",installed,"& PATHTOMSI1
              	saveLog strLogData,strLogFile
              End If              
            RunMsi = ""          
        End If
        If pck2 = false Then
                RunMsi = "MSIEXEC /i " & PATHTOMSI2 & " /qb" '<-------changes to msi command line options can be done here
              oShell.run RunMsi,1,True
              If Err.Number = 0 Then 
              	strLogData = now() & ",installed," & PATHTOMSI2
              	saveLog strLogData,strLogFile
              End If
            RunMsi = ""
        End If        
set installer = Nothing
Set oShell = Nothing
 
Private Sub saveLog(strMSIinfo,strLog)
Dim objFSO, strComputerName,objTextFile
Const ForAppending = 8
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
	strComputerName = WshNetwork.ComputerName
	strMSIInfo = strMSIinfo & "," & strComputerName
Set objTextFile = objFSO.OpenTextFile(strLog, ForAppending, True)
	objTextFile.WriteLine(strMSIinfo)
	objTextFile.Close
Set ObjFSO = Nothing
Set objTextFile = Nothing
Set WshNetwork = Nothing
End Sub 

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you are creting two installs with this,  a complied one to allow admin install without putting creditials in clear text, and the script to check for the app and call the first if an install is needed.


zf
THANKS...
This code here "ID: 22111375" is the one i need to create an exe.
Then use the latest code to trigger.
So totally 2 files involved here. Am i right....
I have been reading a lot of times before responding thinking i could understand better.
So the vbs will call the exe and run as administrator on the msi and install on logon.

"This code here "ID: 22111375" is the one i need to create an exe."   <---  yes vb code to compile admin account install.exe

"Then use the latest code to trigger."  <---- ID:22112983 yes this last script calls the vb6 exe after checking if app is installed

"So totally 2 files involved here. Am i right...."  <-- actually there is three
    (1) Your custom MSI
    (2) vb6 app calling (file 1) with admin account install
    (3) login script to check if app is installed if not calls ( file 2)

"So the vbs will call the exe and run as administrator on the msi and install on logon."  <----you got it. :-)




zf

THX Shall check and get back
Zoofan one question when we have the msi path in the vbs why should we have this loine here
    strExecCommand = "commandToExec" 'Example "MSIEXEC /i \\server\share$\myown.msi /qn"
should this also be in the vb6 file which i need to convert to exe.?
Zoofan one question when we have the msi path in the vbs why should we have this loine here
    strExecCommand = "commandToExec" 'Example "MSIEXEC /i \\server\share$\myown.msi /qn"
should this also be in the vb6 file which i need to convert to exe.?
Yes it is in the vb6 app,  that is in fact the line of code FROM THE vb6 app NOT the script.

"Zoofan one question when we have the msi path in the vbs why should we have this loine here"

This line is NOT in the vbs......   "strExecCommand = "commandToExec" 'Example "MSIEXEC /i \\server\share$\myown.msi /qn""


you should be using script from ID:22112983
you should be using vb6 app from  ID:22111375


:-)

Ill be up for about 20 more min if you dont understand let me know.


zf
Lines 5 and 6 from script ID:22112983 set the execute command for the vbs by calling the vb6 app.


zf
Zoofan just did all as you said. But the exe when executed gives these error.
---------------------------
RunAsAdmin
---------------------------
CreateProcessWithLogonW() failed with error 0 :
---------------------------
OK  
---------------------------

I even ran the vbs its triggering correctly to the exe's i get 2 of the above error boxes.
 
Zoofan just did all as you said. But the exe when executed gives these error.
---------------------------
RunAsAdmin
---------------------------
CreateProcessWithLogonW() failed with error 0 :
---------------------------
OK  
---------------------------

I even ran the vbs its triggering correctly to the exe's i get 2 of the above error boxes.
 
Check to make sure you have coded the username, password and domain name correctly.  Case sensative, no mistakes in copy or paste of code etc etc,  I use this daily on both 00 and 03 AD domains
*NOTE the domain name is the netbios name NOT the FQDN

IE: the domain name you would see from
 open a command prompt and type 'set' no ticks press enter environment variable 'USERDOMAIN' is your netbios domain name.

zf
another note.

    strUsername = "Username" 'Username in the domain with rights to do what you need
    strPassword = "Password" 'Password for above account
    strNetBIOSDomainName = "Domain" 'This is the 15char max name used in network places NOT your FQDN
    strExecCommand = "commandToExec" 'Example "MSIEXEC /i \\server\share$\myown.msi /qn"

 strUsername = "AdminInstaller"    <---- these changes all need to keep the quotes
 strPassword = "myPass1Q!"
 strNetBIOSDomainName = "NetBioD"
 strExecCommand = "calc.exe"
Another note, remebering the question you asked yesturday about blocking users from accessing your computer from the netowork, make sure your using an account which has the ability to login into the machine the script is executing from!!!!



zf



goes without saying but(as it is the point of the question), But  also the ability to install the app.


zf
zoofan thanks...I shall check all these in some time and revert back...
 
zoofan thanks...I shall check all these in some time and revert back...
 
ok, am out for the night will check back tommorrow.


zf
zoofan just testing this on my test domain
 
 strUsername = "administrator" 'Username in the domain with rights to do what you need
    strPassword = "abc123" 'Password for above account
    strNetBIOSDomainName = "webserver" 'This is the 15char max name used in network places NOT your FQDN
    strExecCommand = "MSIEXEC /i \\Test\msi\WordStartupTemplate.msi /qn" 'Example "MSIEXEC /i \\server\share$\myown.msi /qn"
 
It gives the same error. Is there anything wrong here
zoofan just testing this on my test domain
 
 strUsername = "administrator" 'Username in the domain with rights to do what you need
    strPassword = "abc123" 'Password for above account
    strNetBIOSDomainName = "webserver" 'This is the 15char max name used in network places NOT your FQDN
    strExecCommand = "MSIEXEC /i \\Test\msi\WordStartupTemplate.msi /qn" 'Example "MSIEXEC /i \\server\share$\myown.msi /qn"
 
It gives the same error. Is there anything wrong here
Well assuming the variable information is correct and that it is running in a domain then no.  I copied and pasted the vb6 code from the snippet window and reran it on a 2k server DC an 03 server DC and an xp client in the 03 AD it worked fine.  So Im at a loss.


You are authenticating this back to a Domain user account and a Domain for testing NOT a standalone server correct?


zf
Thanks a lot zoofan worked fine for me...
You were of great help on this.... Thank U
Your very welcome,  what was the cause of the error?

zf
I was testing it on a machine that is different from the domain.
:-(
 
zoofan can you put in this solution here
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Q_23601083.html
so i can close the post
Done,  thank you.


zf