Link to home
Create AccountLog in
Avatar of PKI_Program_Office

asked on

automate uninstall/installs through vb script

I release the code for uninstalling a program is as follows:

Set oWShell = CreateObject("Wscript.Shell")

      'Uninstall the product and wait for it to finish
      oWShell.Run "msiexec /x ""{74738135-38D6-4ABD-A2BF-A86744971607}"" /passive /norestart", 8, True

Although, there is certain problem that I am facing.  At times, when I try to uninstall this particular program, I receive an error stating "The feature you are trying to use is on a network resource that is unavailable.  Click OK to try again, or enter an alternate path to a folder containing the installation package 'my_example_file[1].msi' in the box below."

I have found that this error occurs when the install source folder has been deleted.  The install source will typically be from a temporary internet files folder so if the user deletes all temporary internet files it becomes a problem.  I understand that all I need to do is point the windows installer to the correct source path and the file must have the exact name as specified.  Is there a way to automate this whole process that if I run an uninstall script and I receive the error described above, it will then download the correct file from a known ftp source and save it with the correct naming convention?  The exact naming of the file is located in this area of the registry:

Value name = PackageName
Value data = my_example_file[1].msi (in this particular example)

But I am interested in extracting the exact value data name and applying it to the name of the .msi that I just downloaded from the ftp site and then having the windows installer point to this file.  Therefore, never receiving the error in the first place.

The vb script below is the basic code that will uninstall the product I want if the proper soucefile exists.  I would like to edit this code to addin the automated features I described above.  Thanks.
Avatar of spinzr0
Flag of United States of America image

If you're downloading the MSI, it would be simpler to just call the uninstall to the MSI path rather than to do this extra logic.  You can copy the file down, then just call:

oWShell.Run "msiexec /x ""C:\mymsi.msi"" /passive /norestart", 8, True

Additionally, if you have the MSI in a shared location, you can also modify the key HKEY_CLASSES_ROOT\Installer\Products\531837476D83DBA42AFB8A7644796170\SourceList\LastUsedSource to point to your shared location.
Hi, this article should help:

How to programmatically update the source list for an installed Windows Installer package

So, with that information added to your script, you should be able to use something like the code below.


Set objShell = CreateObject("WScript.Shell")
Set objWindowsInstaller = CreateObject("WindowsInstaller.Installer")
' Specify the Product ID to uninstall
strProductID = "{74738135-38D6-4ABD-A2BF-A86744971607}"
' Specify an alternate source path
strSourcePath = "\\server\share\Apps\"
If Right(strSourcePath, 1) <> "\" Then strSourcePath = strSourcePath & "\"
' Add the alternate source path to the Windows Installer package
objWindowsInstaller.AddSource strProductID, "", strSourcePath
' Uninstall the product and wait for it to finish
objShell.Run "msiexec /x """ & strProductID & """ /passive /norestart", 8, True
' Force the installer to search the new source list
objWindowsInstaller.ForceSourceListResolution strProductID, ""

Open in new window

Avatar of PKI_Program_Office


Rob - Thanks for the help.  I think the only problem Im dealing with now is that the "Package Name" listed in the registry (see below) should be "my_example_file.msi" and not "my_example_file[1].msi.  It seems that windows changes the name of the file when it gets installed.  So I was hoping to be able to change the package names value data to "my_example_file.msi" without the "[1]" and then point the install source to the correct share.  How could I do that in this vb script that you provided?  Thanks.

Value name = PackageName
Value data = my_example_file[1].msi (in this particular example)

Avatar of RobSampson
Flag of Australia image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account