bsharath
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
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
ASKER
zoofan
Will i be able to achieve the same thing with an compiled exe.
Will logon scripts work with exe?
Will i be able to achieve the same thing with an compiled exe.
Will logon scripts work with exe?
ASKER
zoofan
Will i be able to achieve the same thing with an compiled exe.
Will logon scripts work with exe?
Will i be able to achieve the same thing with an compiled exe.
Will logon scripts work with exe?
Yes
zf
zf
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
if you need help calling in your login script let me know.
zf
ASKER
Can you give me the calling and waiting as well
As noted below
zf
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
ASKER
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
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
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)
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
ASKER
>>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
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
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
'***********************************************************
ASKER
zoofan thanks i got an idea.
Below is the login script that i use now
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
zf
ASKER
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.
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
ASKER
THX Shall check and get back
ASKER
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.?
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.?
ASKER
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.?
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
"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
zf
ASKER
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.
--------------------------
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.
ASKER
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.
--------------------------
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
*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"
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
zf
goes without saying but(as it is the point of the question), But also the ability to install the app.
zf
zf
ASKER
zoofan thanks...I shall check all these in some time and revert back...
ASKER
zoofan thanks...I shall check all these in some time and revert back...
ok, am out for the night will check back tommorrow.
zf
zf
ASKER
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\WordStartupTemp late.msi /qn" 'Example "MSIEXEC /i \\server\share$\myown.msi /qn"
It gives the same error. Is there anything wrong here
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\WordStartupTemp
It gives the same error. Is there anything wrong here
ASKER
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\WordStartupTemp late.msi /qn" 'Example "MSIEXEC /i \\server\share$\myown.msi /qn"
It gives the same error. Is there anything wrong here
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\WordStartupTemp
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
You are authenticating this back to a Domain user account and a Domain for testing NOT a standalone server correct?
zf
ASKER
Thanks a lot zoofan worked fine for me...
You were of great help on this.... Thank U
You were of great help on this.... Thank U
Your very welcome, what was the cause of the error?
zf
zf
ASKER
I was testing it on a machine that is different from the domain.
:-(
:-(
ASKER
zoofan can you put in this solution here
http://www.experts-exchang e.com/OS/M icrosoft_O perating_S ystems/Q_2 3601083.ht ml
so i can close the post
http://www.experts-exchang
so i can close the post
Done, thank you.
zf
zf
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