Error-codes from Windows Installer ?!?!?! 
Author Message
 Error-codes from Windows Installer ?!?!?!

Hi guys :)

I've made the following script, which basically prevents a user from
pressing cancel, when you install .msi packages with Windows Installer
(There is no basic UI, with no cancel-button).

----------------------------------------
Option Explicit

'---

Dim WshShell, FSO, MWI
Dim strCurPath, strPackage, strPkg01, strPkg02
Dim strPopTxt, strPopTitle, vbCritical, strMSI, strUnInst, strPkg03,
strSilBas, strSuccess

'---

Set WshShell=WScript.CreateObject("WScript.Shell")
Set FSO=CreateObject("Scripting.FileSystemObject")
Set MWI=CreateObject("WindowsInstaller.Installer")

'---

strCurPath = FSO.GetAbsolutePathName(".")
strPkg01 = "\cwmodels103rev02\cwmodels103rev02.msi"
strPkg02 = "\cw2000_auto-as\cw2000_auto-as.msi"
strPkg03 = "\cwmodels103\cwmodels103.msi"
vbCritical = 16
strPopTxt = "You're not supposed to cancel this installation !" & vbCrLf
& "The installation will restart in 10 seconds from now, or when" &
vbCrLf & "you press the OK button."
strPopTitle = "Installation Wrapper v1.0"
strUnInst = " /x "
strSilBas = " /qb"
strMSI = "%SystemRoot%\System32\msiexec.exe"

'---

WshShell.Run strMSI & strUnInst & strCurPath & strPkg03 &
strSilBas,1,TRUE
WScript.Sleep (1000)

'---
strPackage = strCurPath & strPkg01
InstallPkg strPackage

'---
strPackage = strCurPath & strPkg02
InstallPkg strPackage

Sub InstallPkg (strPackage)
Dim valRC
valRC = 1
Do While valRC <> 0
  On Error Resume Next
  MWI.InstallProduct strPackage
  valRC = Err.Number
  If valRC <> 0 Then
    WshShell.Popup strPopTxt,10,strPopTitle,vbCritical
    valRC=Err.Number
    Err.Clear
  End If
Loop
valRC = 1
End Sub

'---

WScript.Quit
----------------------------------------

Ok, that was for the basic understanding of the script. Now, I've tried
making a Sub that would un-install an installed package. That would look
something like:

strPackage = strMSI & strUnInst & strCurPath & strPkg03 & strSilBas

Sub SubInstallPkg (strPackage)
Dim valRC
valRC = 1
Do While valRC <> 0
  On Error Resume Next
  WshShell.Run strPackage,1,TRUE
  WScript.Sleep (1000)
  valRC = Err.Number
  If valRC <> 0 Then
    WshShell.Popup strPopTxt,10,strPopTitle,vbCritical
    valRC=Err.Number
    Err.Clear
  End If
Loop
valRC = 1
End Sub

Ok... It works fine when installing. I'm using a Windows Installer
object for that, and a method through that object.

However, if I click cancel when un-installing, it just hops out of the
Sub, and starts installing. No popup box, no retry, no nothing. Very
unlike the installation-sub.

I then made a msgbox, and found out that even if I press cancel when un-
installing, the error-code returned, is STILL 0 ! Which then explains
why it jumps out of the Sub.

How do I do the un-install routine then ? Anyone have an idea ? It would
be really neat, to be able to protect the un-install sequence, just like
I can with the installation sequence.

Oh, and for those of you unfamiliar with these terms: The reason for all
of this to begin with, is that at my job we use SMS to distribute
software under Windows 2000. Most of the time, that's done with .msi
packages. However, the .msi format/Windows Installer has the big
disadvantage that the users can cancel the installation of the software
when done via SMS. SMS then doesn't restart the installation. Which all
in all causes a lot of helpdesk calls. We could of course do the
installation completely without UI, but that's not an option, as the
user MUST know that something is being done on the machine. Or they'll
just start using it...

Also, I find it very odd, that the Windows Installer object provides a
method for installing software... but none for removal ?

Anyway, hope someone understands what I mean... and knows how to help
out :)

--
Jacob S. Nielsen
http://www.*-*-*.com/



Mon, 04 Aug 2003 01:11:59 GMT  
 Error-codes from Windows Installer ?!?!?!
The reason you are having problems is you are looking for the err object to
be set.  What you want to do is look at the return value from the process
you start.

Use it like this:
retval = WshShell.Run (appname, 1, 1)
Then check the return value of the application.  Look at the windows
installer documentation for valid return codes.  You can also find out if
the install requires a reboot etc. this way.

-Tony



Quote:
> Hi guys :)

> I've made the following script, which basically prevents a user from
> pressing cancel, when you install .msi packages with Windows Installer
> (There is no basic UI, with no cancel-button).

> ----------------------------------------
> Option Explicit

> '---

> Dim WshShell, FSO, MWI
> Dim strCurPath, strPackage, strPkg01, strPkg02
> Dim strPopTxt, strPopTitle, vbCritical, strMSI, strUnInst, strPkg03,
> strSilBas, strSuccess

> '---

> Set WshShell=WScript.CreateObject("WScript.Shell")
> Set FSO=CreateObject("Scripting.FileSystemObject")
> Set MWI=CreateObject("WindowsInstaller.Installer")

> '---

> strCurPath = FSO.GetAbsolutePathName(".")
> strPkg01 = "\cwmodels103rev02\cwmodels103rev02.msi"
> strPkg02 = "\cw2000_auto-as\cw2000_auto-as.msi"
> strPkg03 = "\cwmodels103\cwmodels103.msi"
> vbCritical = 16
> strPopTxt = "You're not supposed to cancel this installation !" & vbCrLf
> & "The installation will restart in 10 seconds from now, or when" &
> vbCrLf & "you press the OK button."
> strPopTitle = "Installation Wrapper v1.0"
> strUnInst = " /x "
> strSilBas = " /qb"
> strMSI = "%SystemRoot%\System32\msiexec.exe"

> '---

> WshShell.Run strMSI & strUnInst & strCurPath & strPkg03 &
> strSilBas,1,TRUE
> WScript.Sleep (1000)

> '---
> strPackage = strCurPath & strPkg01
> InstallPkg strPackage

> '---
> strPackage = strCurPath & strPkg02
> InstallPkg strPackage

> Sub InstallPkg (strPackage)
> Dim valRC
> valRC = 1
> Do While valRC <> 0
>   On Error Resume Next
>   MWI.InstallProduct strPackage
>   valRC = Err.Number
>   If valRC <> 0 Then
>     WshShell.Popup strPopTxt,10,strPopTitle,vbCritical
>     valRC=Err.Number
>     Err.Clear
>   End If
> Loop
> valRC = 1
> End Sub

> '---

> WScript.Quit
> ----------------------------------------

> Ok, that was for the basic understanding of the script. Now, I've tried
> making a Sub that would un-install an installed package. That would look
> something like:

> strPackage = strMSI & strUnInst & strCurPath & strPkg03 & strSilBas

> Sub SubInstallPkg (strPackage)
> Dim valRC
> valRC = 1
> Do While valRC <> 0
>   On Error Resume Next
>   WshShell.Run strPackage,1,TRUE
>   WScript.Sleep (1000)
>   valRC = Err.Number
>   If valRC <> 0 Then
>     WshShell.Popup strPopTxt,10,strPopTitle,vbCritical
>     valRC=Err.Number
>     Err.Clear
>   End If
> Loop
> valRC = 1
> End Sub

> Ok... It works fine when installing. I'm using a Windows Installer
> object for that, and a method through that object.

> However, if I click cancel when un-installing, it just hops out of the
> Sub, and starts installing. No popup box, no retry, no nothing. Very
> unlike the installation-sub.

> I then made a msgbox, and found out that even if I press cancel when un-
> installing, the error-code returned, is STILL 0 ! Which then explains
> why it jumps out of the Sub.

> How do I do the un-install routine then ? Anyone have an idea ? It would
> be really neat, to be able to protect the un-install sequence, just like
> I can with the installation sequence.

> Oh, and for those of you unfamiliar with these terms: The reason for all
> of this to begin with, is that at my job we use SMS to distribute
> software under Windows 2000. Most of the time, that's done with .msi
> packages. However, the .msi format/Windows Installer has the big
> disadvantage that the users can cancel the installation of the software
> when done via SMS. SMS then doesn't restart the installation. Which all
> in all causes a lot of helpdesk calls. We could of course do the
> installation completely without UI, but that's not an option, as the
> user MUST know that something is being done on the machine. Or they'll
> just start using it...

> Also, I find it very odd, that the Windows Installer object provides a
> method for installing software... but none for removal ?

> Anyway, hope someone understands what I mean... and knows how to help
> out :)

> --
> Jacob S. Nielsen
> http://www.modular-juice.net



Tue, 05 Aug 2003 05:11:59 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Windows Installer or Script based installer????

2. Error while building windows service with installer

3. 2355 error on using windows installer with vb assistant

4. Windows Installer and CR merge module error

5. Executing an installation using script/Wise for Windows Installer

6. JScript from an msi, Windows Installer package

7. Executing an installation using script/Wise for Windows Installer

8. Windows Installer--VBScript Custom Action

9. ANNOUNCE: izfree Tools for Windows Installer (HTA example)

10. Scripting for Windows Installer problem

11. Windows Installer ans scripting facilities (?)

12. Checking for windows installer version

 

 
Powered by phpBB® Forum Software