Tuesday, December 8, 2009

New version installer template Version 1.2

Updated the installer template to a new version.
Changes are:

ADDED:
isApplicationInstalled : Check if an application is installed.
isApplicationInstalledGUID : Check if an application is installed by its Identifier.
Usefull when the Add Remove Programname is not unique
isProcessActive : Check if a process is active.
MODIFIED:
uninstallAppGUID : Fixed the exit code to be unique.

Download link: Install_Template-1.2.vbs

Changes are below:

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2009
'
' NAME: Installer script template V1.2
' AUTHOR: Bas Steelooper , Steelooper Consulting
' DATE  : 08-12-2009
'
'  Modifications
'  V1.1
' ADDED:
'   uninstallAppGUID : Uninstall an application by its Identifier.
'       Usefull when the Add Remove Programname is not unique
' MODIFIED:
'  s_ForceUseCSCript : added variable forceCscriptSilent.
'       If set to TRUE the script will NOT notify the end user that it is being relaunched
'  s_ForceUseCSCript : WSHShell.run modified to hidden.
'       When relaunched the script now doesn't show a cscript window.
'
'  V1.2
' ADDED:
'   isApplicationInstalled : Check if an application is installed.
'   isApplicationInstalledGUID : Check if an application is installed by its Identifier.
'       Usefull when the Add Remove Programname is not unique
'   isProcessActive : Check if a process is active.
' MODIFIED:
'  uninstallAppGUID : Fixed the exit code to be unique.
'
'==========================================================================

........

Const APPVER            = "1.2"

........ 

Sub showHelp()
'===============================================================================
'# Purpose : show help information on how to use the script                    #
'#                                                                             #
'# Modified  in version 1.2                                                    #
'===============================================================================

.....

  If debug Then

.....

    WScript.Echo vbTab & "66600005" & vbTab & " : uninstallAppGUID is called without information" 'added in version 1.2
    WScript.Echo vbTab & "66600006" & vbTab & " : isProcessActive is called without information" 'added in version 1.2
    WScript.Echo vbTab & "66600007" & vbTab & " : isApplicationInstalled is called without information" 'added in version 1.2
    WScript.Echo vbTab & "66600008" & vbTab & " : isApplicationInstalledGUID is called without information" 'added in version 1.2
  End If

.....

End Sub

.........

Function isProcessActive(objWMIService, arrProcName)
'==============================================================================================================================
'# purpose : check if the processes passed to this service are active                                                         #
'# input : objWMIService : initialised object from GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") #
'#         arrProcName : Array which contains the names of the processes to be checked                                        #
'#                       String which contains one name of a process to be checked                                            #
'#                                                                                                                            #
'#  Example: arrProcName = Array("outlook", "communicator", "winword", "excel", "powerpnt", "access")                         #
'#           isProcessActive objWMI, arrProcName                                                                              #

'#                                                                                                                            #
'# Added in version 1.2                                                                                                       #
'==============================================================================================================================
    writeLog "starting isProcessActive", "Starting isProcessActive", "isProcessActive"
 Dim colProcesses, strQuery, procName, first 
    strQuery = "Select * from Win32_Process where "
    first = True

 If IsArray( arrProcName ) Then
        For Each procName In arrProcName 
            If Not first Then
                strQuery = strQuery & "OR "
            End If
            strQuery = strQuery & "Name Like '%"& procName &"%' "
            first = false
        Next
    Else
        If arrProcName = "" Then
            writeLog "ERROR isProcessActive", "ERROR - Started isProcessActive with no Process te check " & _
            "- Terminiting script now with errorcode 66600006", "isProcessActive"
            WScript.Quit (66600006)
        Else
            strQuery = strQuery & "Name Like '%"& arrProcName &"%' "
        End if
    End If
 
 Set colProcesses = objWMIService.ExecQuery(strQuery)
 Dim Process
 isProcessActive = False
 For Each Process In colProcesses
  isProcessActive = True 
 Next
End Function 

..........

Private Sub uninstallAppGUID( objWMIService, arrAppName )

.......

   writeLog "ERROR UNINSTALL","Error uninstalling because no parameter was set. exiting with errorcode 66600005", "uninstallAppGUID" 'fixed in version 1.2

.......

End Sub

Private Function isApplicationInstalled( objWMIService, arrAppName )
'==============================================================================================================================
'# purpose : check if the applications which are given in the input are installed                                             #
'# input : objWMIService : initialised object from GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") #
'#         arrAppName : Array which contains the names of the applications to be checked                                      #
'#                      String which contains one name of a applications to be checked                                        #
'#                                                                                                                            #
'#  Example: arrCheckAppName = Array("Office 2003 Proofing", "Microsoft Office Proof", "visio viewer")                        #
'#           isApplicationInstalled objWMI, arrCheckAppName                                                                   #
'#                                                                                                                            #
'# Added in version 1.2                                                                                                       #
'==============================================================================================================================
    writeLog "starting isApplicationInstalled","starting to run the sub isApplicationInstalled", "isApplicationInstalled"
    Dim colSoftware, objSoftware, strQuery, first, strAppName
    strQuery = "Select * from Win32_Product Where "
    first = True
    on error resume next
    If IsArray( arrAppName ) Then
        For Each strAppName In arrAppName 
            If Not first Then
                strQuery = strQuery & "OR "
            End If
            strQuery = strQuery & "Name Like '%"& strAppName &"%' "
            first = false
        Next
    Else
        If arrAppName = "" Then
            writeLog "ERROR CHECK","Error checking because no parameter was set. exiting with errorcode 66600007", "isApplicationInstalled"
            WScript.Quit (66600007)
        End if
        strQuery = strQuery & "Name Like '%"& arrAppName &"%' "
    End If
    Set colSoftware = objWMIService.ExecQuery (strQuery)
 on error resume next
    isApplicationInstalled = False 
    For Each objSoftware in colSoftware
        writeLog "checking application","Now checking " & objSoftware.Name, "isApplicationInstalled"
        isApplicationInstalled = True 
    Next
    on error goto 0
End Function

Private Function isApplicationInstalledGUID( objWMIService, arrAppName )
'==============================================================================================================================
'# purpose : check if the applications which are given in the input are installed                                             #
'# input : objWMIService : initialised object from GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") #
'#         arrAppName : Array which contains the names of the applications to be checked                                      #
'#                      String which contains one name of a applications to be checked                                        #
'#                                                                                                                            #
'#  Example: arrCheckAppName = Array("{34E9AA45-3D13-4DBD-8BC9-7F06AB39B090}", "{34666A45-3D13-4DBD-8BC9-7F0612345690}")      #
'#           isApplicationInstalledGUID objWMI, arrCheckAppName                                                               #
'#                                                                                                                            #
'# Added in version 1.2                                                                                                       #
'============================================================================================================================== 
 writeLog "starting isApplicationInstalledGUID","starting to run the sub isApplicationInstalledGUID", "isApplicationInstalledGUID"
 Dim colSoftware, objSoftware, strQuery, first, strAppName
 strQuery = "Select * from Win32_Product Where "
 first = True
 
 If IsArray( arrAppName ) Then
  For Each strAppName In arrAppName 
   If Not first Then
    strQuery = strQuery & "OR "
   End If
   strQuery = strQuery & "IdentifyingNumber = '%"& strAppName &"%' "
   first = false
  Next
 Else
  If arrAppName = "" Then
   writeLog "ERROR CHECK","Error checking because no parameter was set. exiting with errorcode 66600008", "isApplicationInstalledGUID"
   WScript.Quit (66600008)
  End if
  strQuery = strQuery & "IdentifyingNumber = '%"& arrAppName &"%' "
 End If
 Set colSoftware = objWMIService.ExecQuery (strQuery)
 on error resume next
    isApplicationInstalled = False 
    For Each objSoftware in colSoftware
        writeLog "checking application","Now checking " & objSoftware.Name, "isApplicationInstalledGUID"
        isApplicationInstalled = True 
    Next
 on error goto 0
End Function

Use it freely if you want. But please post here if you do.

No comments:

Post a Comment