Video Screencast Help

Capturing Exit Codes While Installing/Uninstalling Applications

Created: 24 Jul 2012 | 4 comments
Language Translations
Param_C's picture
+5 5 Votes
Login to vote

I came across a strange error code recently with an application called DYMO label printer. We packaged this application along with the device driver. We have used DPInst.exe to install the Device Driver.

Once the application and the driver installed, we got an error code 256 from software delivery tool. Deployment Team reported this application deployment as a FAILURE. However when we troubleshoot this issue we found a conflicting information. The deployment of the application and the driver is in fact successful. However the EXIT CODE given by the installation script was 256 which was captured in the deployment tool.     

During our troubleshooting we came to know that the EXIT CODE was in fact returned by DPInst.exe, which was used to install the device driver. When we manually installed the driver in UI mode, we can see the driver installed successfully.

This clearly indicates that the Driver indeed installed successfully. But why 256 EXIT CODE? We did find the answer to this question. :-) 

DPinst.exe returns exit code 256 (DWORD: 0x00000100) if the driver installation is successful as per the below article from Microsoft:   

http://msdn.microsoft.com/en-us/library/windows/hardware/ff544790(v=vs.85).aspx  
 
So EXIT CODE from DPInst.exe was indeed success. In order to turn this exit code into success, we have modified our Installation script logic to turn 256 EXIT CODE into success. 
 
I'm sure most of you guys are using installation scripts not only to install or uninstall packaged applications but also for so many other activities such as
1. creating installation log files
2. returning exit codes to SWD 
3. preinstall and post install checks
4. running Altiris Inventory Agent etc...
 
So I have created few install and uninstall script that are generic in nature and can me modified according to the requirement. These scripts allows us to capture EXIT CODES.
 

1. Visual Basic Script Install [Install.vbs]: 

'---------------------------------------------------------------------------------------------------

'Script to install an application [MSI & MST] and return the exit code

'---------------------------------------------------------------------------------------------------

Dim oShell, ofso, ScriptDIr, ErrorCode 
 
Set oShell = CreateObject("WScript.Shell")
Set ofso = CreateObject("Scripting.FileSystemObject")
ScriptDIr = oFSO.GetParentFolderName(Wscript.ScriptFullName)
 
ErrorCode = oShell.Run("MSIEXEC /I " & Chr(34) & ScriptDIr & "\SETUP.MSI" & Chr(34) & " TRANSFORMS=" & Chr(34) & ScriptDIr & "\SETUP.MST" & Chr(34) & " /L*V C:\INSTA_LOGS\SETUP_Install.LOG /QB!-", 0, True) 
WScript.Quit(ErrorCode)
 
Set oShell = Nothing
Set ofso = Nothing
Set oReg = Nothing
 
 
2. Visual Basic Script to Uninstall [Uninstall.vbs]: 

'---------------------------------------------------------------------------------------------------

'Script to uninstall an application [MSI & MST] and return the exit code

'---------------------------------------------------------------------------------------------------

Dim oShell, ofso, ScriptDIr, ErrorCode 
 
Set oShell = CreateObject("WScript.Shell")
Set ofso = CreateObject("Scripting.FileSystemObject")
ScriptDIr = oFSO.GetParentFolderName(Wscript.ScriptFullName)
 
ErrorCode = oShell.Run("MSIEXEC /X {PRODUCT_CODE} & " /L*V C:\INSTA_LOGS\SETUP_Uninstall.LOG /QB!-", 0, True) 
WScript.Quit(ErrorCode)
 
Set oShell = Nothing
Set ofso = Nothing
Set oReg = Nothing
 
 
3. Batch/Command Script to Install [Install.bat or Install.cmd]: 

'---------------------------------------------------------------------------------------------------

'Script to install an application [MSI & MST] and return the exit code

'---------------------------------------------------------------------------------------------------

Set MSIName=SETUP.MSI
Set MSTName=SETUP.MST
Set LogsFolder="C:\INST_LOGS\SETUP_Install.log"
 
if not exist "C:\INST_LOGS" md "C:\INST_LOGS"
MSIEXEC.EXE /I "%~dp0%MSIName%" TRANSFORMS="%~dp0%MSTName%" /qb-! /l*v %LogsFolder%
 
set msierror=%errorlevel%
if %msierror%==0 goto :Misc
if %msierror%==1641 goto :Misc
if %msierror%==3010 goto :Misc
 
goto :ERROR
 
:Misc
@echo Successfully Installed the Application.
goto :Einde
 
:ERROR
@echo Error Code is %msierror% if exist %LogFile% type %LogFile%
goto :Einde
 
:Einde
@echo Job ended at %date% %Time%
Exit %msierror%

4. Batch/Command Script to Uninstall [Uninstall.bat or Uninstall.cmd]: 

'---------------------------------------------------------------------------------------------------

'Script to install an application [MSI & MST] and return the exit code

'---------------------------------------------------------------------------------------------------

Set LogsFolder="C:\INST_LOGS\SETUP_Uninstall.log"
 
if not exist "C:\INST_LOGS" md "C:\INST_LOGS"
MSIEXEC.EXE /X {PRODUCT_CODE} /qb-! /l*v %LogsFolder%
 
set msierror=%errorlevel%
if %msierror%==0 goto :Misc
if %msierror%==1641 goto :Misc
if %msierror%==3010 goto :Misc
 
goto :ERROR
 
:Misc
@echo Successfully Uninstalled the Application.
goto :Einde
 
:ERROR
@echo Error Code is %msierror% if exist %LogFile% type %LogFile%
goto :Einde
 
:Einde
@echo Job ended at %date% %Time%
Exit %msierror%
 
 
Hope this helps. 
 
Cheers,
Param Chaganti

Comments 4 CommentsJump to latest comment

CableGuy41's picture

nice script templates

Thanks,

CableGuy
Do not forget to mark a SOLUTION

0
Login to vote
CableGuy41's picture

1

Thanks,

CableGuy
Do not forget to mark a SOLUTION

0
Login to vote
derraven's picture

Hi,

Usually MSI technology allows you to create log files by default without passing any script at all.

Installation Example:

msiexec /i "YOUR.msi" /qb! /L*V C:\Logs\YourProduct-Install.log {Will let you display the installation wizard}

msiexec /i "YOUR.msi" TRANSFORMS="YOUR.mst" /qn /L*V C:\Logs\YourProduct-Install.log  {Will do a silent install}

This line will be able to do the job on your SCCM 2012 without any troubles and at the same time it will create the log file on the path you can specify. The example will put the log file inside >> C:\Logs\

Check your providers documentation as they sometimes have special tools to create a product for corporate deployments. Example: Adobe Products use AMEE to create the package.

To uninstall your product is easy too the only thing you need to do is search your product GUID and voila here you go the uninstall string:

msiexec /x {Product GUID} /qn /L*V C:\Logs\YourProduct-Uninstall.log

But the challenge starts when you have some installers with (.EXE) files that doesn't extracts their MSI's or they are not standard that they even do not support a simple log file creation. Sometimes this installers creates their log files either on the installation folder or somewhere else on your drive. The developpers creates hard coding to drop this log files intentionnaly as for they are easy to troubleshoot their products but they don't realize that we on software packaging // deployment at a large scale we have to prove that the application was successfully installed or which was the errors. So a VBS will be a good option to help and control somehow this cases.

But for simple MSI's the best practices are to use the standard commands.

Kind Regards.

Joel EG.

0
Login to vote
derraven's picture

By the way to install Dymo 8.5.1.1814

I used the following CMD on SCCM as a Script Installer.

@echo off

DLS8Setup.8.5.1.exe /s

for /f %%u in ('dir /b C:\Users') do (
  mkdir "C:\Users\%%u\AppData\Local\Sanford,_L.P\DLS.exe_Url_oytsydlkqagtfrul0qdbmkyn2y0toxat\8.5.1.1814"
  mkdir "C:\Users\%%u\AppData\Local\Sanford,_L.P\DLS.exe_Url_q0dsxht4oe0yovrhtt0kppdqugmsjweh\8.5.1.1814"
  copy /y "%~dp0\Sanford,_L.P\DLS.exe_Url_q0dsxht4oe0yovrhtt0kppdqugmsjweh\8.5.1.1814\user.config" "C:\Users\%%u\AppData\Local\Sanford,_L.P\DLS.exe_Url_q0dsxht4oe0yovrhtt0kppdqugmsjweh\8.5.1.1814\user.config"
)

exit /B %EXIT_CODE%

Notice: The file "user.config" contains the per User settings to bypass some of the wizard questions after launching the application. Source >> http://www.itninja.com/software/sanford-l-p/label-...

Regards.

0
Login to vote