[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do i run any MSI file in /quiet /passive mode without getting failures in the vbscript

Posted on 2014-08-22
11
Medium Priority
?
1,890 Views
Last Modified: 2014-08-25
Good evening Experts,
I have been fighting with a bit of code for a couple of hours, and after some research on google , I know what the fix is, but its still not working, so I am here to get your expertise. Many eyes and brains are better than  one set of eyes and brain.

I am attempting to install TightVnc.exe (64bit) on my local machine. Sure , I can simply install it manually , but that is not the goal that I am looking to achieve. I want to launch my script and have it just install in /quiet /passive mode. Done.


The Facts:

I already have a script that I can install any number of MSI files to remote machines , including TightVnc. Here is the code for clarity:

 Const MAXIMIZE_WINDOW = 0
 Computers = Array("PINKLADY")
Set objShell = WScript.CreateObject("WScript.Shell")
wbemImpersonationLevelImpersonate = 3
wbemAuthenticationLevelPktPrivacy = 6
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
On Error Resume Next 
For Each Computer In Computers
	Set objService = objLocator.ConnectServer _
	     (Computer, "root\cimv2", "ADMINISTRATOR", "THANnos08")
     
	objService.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
	objservice.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacy
	
	App="tightvnc-2.7.10-setup-64bit.msi"
	
	objShell.Run "%COMSPEC% /c xcopy  I:\!DOWNLOAD\UtilsMsi\MSI\" & App & " \\" & Computer & "\Users\Public\Documents\  /c /q /r /y" , MAXIMIZE_WINDOW
	
	WScript.Sleep(5000)
	WScript.Echo "Attempting to Install " & App & " on " & Computer & "." 
	
	Set objSoftware = objService.Get("Win32_Product")
	
	errReturn = objSoftware.Install("c:\Users\Public\Documents\tightvnc-2.7.10-setup-64bit.msi",,True)
	If errReturn <> 0 Then
	    Wscript.Echo APP & " was not installed on " & Computer & " the error code = " & errReturn
	    Wscript.Echo "The error returned = " & errReturn
	Else
		WScript.Echo
		WScript.Echo
		Wscript.Echo APP & " was successfully installed on " & Computer & ". the error code  = " & errReturn
		WScript.Echo
		WScript.Echo
	End If
Next 

Open in new window


This code can install any number of TightVnc ( or any number of other MSI software) to remote machines. This just works.

The Problem

The code above wont allow for a local install of the TightVnc installation. Even when I take the credential out it still doesn't install. I get an error 1603 (Fatal install error). So I found a piece of code that does use Windows Instrumentation (WMI) to install locally to a computer. Here is the code:

Installing Software
Computer Assets, Listing 8.14

[b]Description
Installs a hypothetical application Database.msi on the local computer. This script can only be used to install Windows Installer applications (applications installed using a .msi file).[/b]

Script Code 

Const ALL_USERS = True
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install("I:\DOWNLOAD\UtilsMsi\MSI\tightvnc.msi", , ALL_USERS)

Open in new window


After running this code , the errReturn = 1603
The following links speaks to error 1603: http://msdn.microsoft.com/en-us/library/aa390890(v=vs.85).aspx
In short it is a fatal error which tells me nothing.

interestingly enough if I simply run the following command from the command line interpreter it works like a charm:

msiexec.exe /i "I:\DOWNLOAD\UtilsMsi\MSI\tightvnc.msi"  /quiet /passive
alternatevely I can uninstall it with one parameter change:
msiexec.exe /x "I:\DOWNLOAD\UtilsMsi\MSI\tightvnc.msi"  /quiet /passive


Sooooo, what I did was translated the snippet above into vbscript like so:


Const MAXIMIZE_WINDOW = 3
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "%COMSPEC% /k msiexec.exe /i I:\DOWNLOAD\UtilsMsi\MSI\tightvnc.msi  /quiet /passive", MAXIMIZE_WINDOW

Open in new window


Actually it is more of a WSH snippet instead of a vbs snippet, but you get the point. When I run this snippet, it ignores both the /quiet and passive parms. I also tried  /qn.  Note: see the MSIexec parmlist for clarity. Regardless, both parms options were ignored.

I have played with trying to insert ASCII quotations , but that was a bust also. If you are not sure what I mean by ASCII quotations, here is what it looks like :  Chr(34) is the ASCII equivalent of ".


Now lets get started with a potential solution:

I am hoping that one of you experts can see what I am doing wrong.  

In summary:

I want to be able to install an MSI locally without having to install it manually. Pretty simple huh. Well, it's got me stumped, so hellllllp.!!!!
0
Comment
Question by:BLACK THANOS
  • 6
  • 4
11 Comments
 
LVL 84

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 800 total points
ID: 40281204
you need to run this script elevated or you will get a 1625 error
'http://stackoverflow.com/questions/1260740/copy-a-file-from-one-folder-to-another-using-vbscripting
 Const MAXIMIZE_WINDOW = 0
 Computers = Array("Alpha")
Set objShell = WScript.CreateObject("WScript.Shell")
wbemImpersonationLevelImpersonate = 3
wbemAuthenticationLevelPktPrivacy = 6
App="tightvnc-2.7.10-setup-64bit.msi"
DestinationPath = "C:\Users\Public\Documents\"
DestinationFile = DestinationPath & App
SourcePath = "f:\Downloads\"
SourceFile = SourcePath & App
WScript.Echo ("Calling Function with Param")
WScript.Echo("Source:"& SourceFile & "     Destination:" & DestinationPath)
Call CopyFile(SourceFile,DestinationPath)
Call InstallFile()

Function InstallFile
Set fso = Nothing
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
On Error Resume Next 
For Each Computer In Computers
	Set objService = objLocator.ConnectServer _
	     (Computer, "root\cimv2", "ADMINISTRATOR", "THANnos08")
     
	objService.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
	objservice.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacy
	
	WScript.Echo "Attempting to Install " & App & " on " & Computer & "." 
	
	Set objSoftware = objService.Get("Win32_Product")
	Const ALL_USERS = True
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install("c:\Users\Public\Documents\"&App, , ALL_USERS)
	If errReturn <> 0 Then
	    Wscript.Echo APP & " was not installed on " & Computer & " the error code = " & errReturn
	Else
		WScript.Echo
		WScript.Echo
		Wscript.Echo APP & " was successfully installed on " & Computer & ". the error code  = " & errReturn
		WScript.Echo
		WScript.Echo
	End If
Next 
End Function

Sub CopyFile(SourceFile, DestinationFile)
    Set fso = CreateObject("Scripting.FileSystemObject")
    'Check to see if the file already exists in the destination folder
    Dim wasReadOnly
    wasReadOnly = False
    If fso.FileExists(DestinationFile) Then
        'Check to see if the file is read-only
        If fso.GetFile(DestinationFile).Attributes And 1 Then 
            'The file exists and is read-only.
            WScript.Echo "Removing the read-only attribute"
            'Remove the read-only attribute
            fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes - 1
            wasReadOnly = True
        End If

        WScript.Echo "Deleting the file"
        fso.DeleteFile DestinationFile, True
    End If
    'Copy the file
    WScript.Echo "Copying " & SourceFile & " to " & DestinationFile
    fso.CopyFile SourceFile, DestinationFile, True
    If wasReadOnly Then
        'Reapply the read-only attribute
        fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes + 1
    End If
    Set fso = Nothing
End Sub

Open in new window

0
 

Author Comment

by:BLACK THANOS
ID: 40281632
Good morning David,

I almost gave up on anyone responding to this question , as it has been two days since I posted it. Regardless, I am thrilled that you have taken time to help me with my code snippet.  Here is my problem with your code. First,  I have to study it and make sure it works on my local workstation. Secondly, while I was waiting for a response , I played with three lines of code I created and modified it to look like this:

  Const MAXIMIZE_WINDOW = 0
Set net = WScript.CreateObject("WScript.Network")
local=net.ComputerName
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "%COMSPEC% /c I:\ScriptFiles\PsExec.exe \\" & local & "  -u Administrator -p ""THANnos08""  msiexec.exe /i " &chr(34)& "I:\ScriptFiles\tightvnc.msi" &Chr(34)& "/quiet /passive" , MAXIMIZE_WINDOW
  

Open in new window


Third and finally, I like to keep it simple. My updated code in the snippet above just works. Done.
I wanted a way to install a piece of software locally without a lot of code. Albeit , your thirty seven lines of code are
in no way overwhelming , I still have to test it, to see it that will also works. It's always good to have more than one way to solve a problem, and as I am fairly fluent with VBS , WSH and WMI, I will go over your code.

Fourth and finally,

When I posted my code, I fully expected someone to modify that , so I can understand how to elevate credentials for a local machine. Keep in mind I don't have a problem with remote installs, just local ones. Please review MY code:

 Installing Software
Computer Assets, Listing 8.14

[b]Description
Installs a hypothetical application Database.msi on the local computer. This script can only be used to install Windows Installer applications (applications installed using a .msi file).[/b]

Script Code 

Const ALL_USERS = True
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install("I:\DOWNLOAD\UtilsMsi\MSI\tightvnc.msi", , ALL_USERS)
   

Open in new window

and show me how to elevate that in order to run on the local machine . That would have more value to me than looking at someone else's code for thirty minutes or so. For clarity, I appreciate your efforts and will certainly study your code, but kindly look at my code snippet above and see if you can modify that to answer my original request.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40282126
Hi, personally, I don't use Win32_Product to install anything, I prefer the command line method, and I have successfully used this:
Const HIDE_WINDOW = 0
Const MAXIMIZE_WINDOW = 3
strMSI = "c:\Temp\tightvnc-2.7.10-setup-64bit.msi"
strCommand = "msiexec.exe /i """ & strMSI & """ /quiet /passive"
Set objShell = WScript.CreateObject("WScript.Shell")
intReturn = objShell.Run(strCommand, HIDE_WINDOW, True)
WScript.Echo "Return code: " & intReturn

Open in new window


I was, however, able to reproduce your 1603 error, which happened when I used any other switches, like /qn and / or /norestart, which is strange.

Can you try that code and see what it does for you?

Regards,

Rob.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:BLACK THANOS
ID: 40282296
Hi Rob,
It's good to hear from you again. Just to be clear , I have already figured out a couple of ways to successfully install a hypothetical MSI  from vbs, wsh, and wmi. Here is my code for clarity and it simply works. Done.

 Const MAXIMIZE_WINDOW = 0
Set net = WScript.CreateObject("WScript.Network")
local=net.ComputerName
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "%COMSPEC% /c I:\ScriptFiles\PsExec.exe \\" & local & "  -u Administrator -p ""THANnos08""  msiexec.exe /i " &chr(34)& "I:\ScriptFiles\tightvnc.msi" &Chr(34)& "/quiet /passive" , MAXIMIZE_WINDOW

Open in new window


I use primalscript to convert to an exe and encrypt it with a simple cert, so no-one can see the user names and passwords. I wasn't concerned about revealing the passwords here in this forum , as I always change them and re-encrypt when I push out to user workstations.

To my point, all information is valuable and I will certainly test your code snippet, but what I really wanted was for someone to modify the original code snippet:

  Installing Software
Computer Assets, Listing 8.14

[b]Description
Installs a hypothetical application Database.msi on the local computer. This script can only be used to install Windows Installer applications (applications installed using a .msi file).[/b]

Script Code 

Const ALL_USERS = True
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install("I:\DOWNLOAD\UtilsMsi\MSI\tightvnc.msi", , ALL_USERS)
   

Open in new window


I got the snippet out of an old scripting book that I have and just once I would like to see it work for someone. The original Author of the VBS Windows Scripting Guide obviously left something out in order for it to  work for installs locally. It just frustrates me when a simple line of code that should work doesn't. Some of the command are probably degraded and are not supported but , I have found no proof of this.

For completeness , as you've read above I have solutions for installing MSI 's  remotely and locally, but I just wanted to see if someone on this forum could support me in getting the code snippet that doesn't work  to work. Nuff Said.

By the way ,

This is Regis , I simply changed my moniker (Avatar) because I am nerdy like that.
Regards,

Regis Hyde , BSB/IS , MIS, Doctoral Learner (DM/IST).
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40282300
Oh hi Reg!  OK, I'll test out the Win32_Product method and see what I can find, although, I have a suspicion that since the command line switches of /qn and /norestart seem to break it, I suspect it may be a problem with the MSI itself....I may open it in Orca and see if there's anything obvious....

Rob.
0
 

Author Comment

by:BLACK THANOS
ID: 40282301
By the way Rob, your code worked only with elevated permissions. I am using windows 8.1 and I had to use PSexec to make it work:

 
Const HIDE_WINDOW = 0
Const MAXIMIZE_WINDOW = 3
Set net = WScript.CreateObject("WScript.Network")
local=net.ComputerName
strMSI = "c:\Temp\tightvnc-2.7.10-setup-64bit.msi"
strCommand = "I:\ScriptFiles\PsExec.exe \\" & local & "  -u Administrator -p ""THANnos08"" msiexec.exe /i """ & strMSI & """ /quiet /passive"
Set objShell = WScript.CreateObject("WScript.Shell")
intReturn = objShell.Run(strCommand, HIDE_WINDOW, True)
WScript.Echo "Return code: " & intReturn

Open in new window


It ran smoothly behind the scenes with only a minimal progress bar, so I never doubted it would work, I just wanted that dreaded code snippet above to work.

If I don't get any responses in the next day for others to try and figure out the code that wont work , I will consider this  thread complete and assign points accordingly.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 1200 total points
ID: 40282311
So I ran this:
strMSI = "c:\Temp\tightvnc-2.7.10-setup-64bit.msi"
strOptions = "REBOOT=REALLYSUPPRESS"
Const ALL_USERS = True
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install(strMSI, strOptions, ALL_USERS)
WScript.Echo errReturn

Open in new window


directly from the VBS, and got the 1603 error.  Looking in the event log I see this:
Product: TightVNC -- Error 1925. You do not have sufficient privileges to complete this installation for all users of the machine. Log on as administrator and then retry this installation.

So, running the script from an elevated command prompt then resulted in the install working normally.

You just need to make sure you are running elevated.

I have also added a registry entry to my machine under
HKCR\VBSFile\Shell\runas\command
in the default value I have put this REG_SZ data
"%SystemRoot%\System32\WScript.exe" "%1" %*

and I can then right click a VBS file and select Run As Administrator to get a quick elevation going.

Regards,

Rob.
0
 

Author Comment

by:BLACK THANOS
ID: 40282476
Nice tip.

I just used Psexec. Just because I am more familiar with it. I love learning new tidbits. I am going to try your reg setting and run the script  in Run As Administrator  mode.  If it works ,then my nagging itch about the code snippet will be scratched. Thank Brother.

regards,
Regis
0
 

Author Closing Comment

by:BLACK THANOS
ID: 40284455
Thank you Gentlemen. Excellent discourse.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40284474
Thanks for the grade.  So was your final conclusion the same as mine, in that the installation requires elevation, and the error otherwise produced is useless (unless you look in the Event logs)?

I guess the code you had from that book may not have been in the times when UAC was in place, or they neglected to mention it.

Rob.
0
 

Author Comment

by:BLACK THANOS
ID: 40284500
You are correct it was definitely a UAC issue and I turned it off temporarily and it worked like a charm, but I don't like turning off UAC , however I do have an easy vbs script thta does it quite nicely. I just prefer to work around UAC by using Psexec.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Suggested Courses

834 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