How gradually to install programs using vb script?

Posted on 2012-09-18
Last Modified: 2014-08-03
Hi Experts,
 my script has to verify the existence of individual programs (whether they are installed on your computer). If they are installed, so the script is skipped. If the computer programs are missing, they run sequentially unattended installation.
 The script must handle:
 1) simply check the existence of programs (installation path can sometimes be even more -see my script)
 2) easy to add a new program to the list of programs to install
 3) gradually start installing individual programs with pre-determined parameters unattended
4) List MsgBox number of programs that need to be installed - for example, the script detects that your computer is missing installed 2 programs and shows MsgBox "Number of programs for installation: 2"

Dim objFSO, oShell, APP_Gimp_PATH_1, APP_Gimp_PATH_2

APP_Gimp_PATH_1 = "C:\Program Files\GIMP 2\bin\gimp-2.8.exe"
APP_Gimp_PATH_2 = "C:\Program Files (x86)\GIMP 2\bin\gimp-2.8.exe"

Set oShell= Wscript.CreateObject("WScript.Shell")
Set objFSO = CreateObject ("Scripting.FileSystemObject")
  If (objFSO.FileExists (APP_Gimp_PATH_1) Or objFSO.FileExists (APP_Gimp_PATH_2)) Then 
      MsgBox "The program is installed."
oShell.Run "RunAs /user:admin@mydomain ""\\\i$\INSTALL\GIMP\gimp-2.8.2-setup-1.exe /SILENT /NOCANCEL /NORESTART"""  
End If

Open in new window

Thank you very much in advance for your help and advice myself I would not make it unfortunately.
Question by:Thomas_Meyer
    LVL 43

    Expert Comment

    by:Steve Knight
    I haven't got time at the mo. to look at this more as on way out but have you looked at if these are standard type apps?  It will build an installer to silently install /reply update whatever you ask it to.

    LVL 65

    Accepted Solution

    Hi, see how this goes.  There is an array to specify your programs, and that's all you need to change.

    Add your programs in the array, in lots of three elements ie, NAME, EXE PATH TO TEST FOR, INSTALLATION COMMAND



    Dim objFSO, oShell
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    strArchitecture = GetOSArchitecture(objWMIService)
    ' Add your programs here, in lots of three elements
    ' The last line in the array must not have a comma at the end
    arrPrograms = Array( _
    	"GIMP 2.8", "%PROGRAMFILES%\GIMP 2\bin\gimp-2.8.exe", "RunAs /user:admin@mydomain ""\\\i$\INSTALL\GIMP\gimp-2.8.2-setup-1.exe /SILENT /NOCANCEL /NORESTART""", _
    	"WinZip 10", "", "%PROGRAMFILES%\Winzip\Winzip.exe", "RunAs /user:admin@mydomain ""\\\i$\INSTALL\Winzip\setup.exe /S""" _
    Set oShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject ("Scripting.FileSystemObject")
    intInstallCount = 0
    strProgramsToInstall = ""
    strInstallCommands = ""
    For intProgram = 0 To UBound(arrPrograms) - 2 Step 3
    	strProgramName = arrPrograms(intProgram)
    	strProgramCommand = arrPrograms(intProgram + 2)
    	blnNeedsInstalling = False
    	If strArchitecture = 32 Then
    		strFileName1 = Replace(arrPrograms(intProgram + 1), "%PROGRAMFILES%", oShell.ExpandEnvironmentStrings("%PROGRAMFILES%"))
    		If objFSO.FileExists(strFileName1) = False Then
    			blnNeedsInstalling = True
    			WScript.Echo strProgramName & " is already installed."
    		End If
    		strFileName1 = Replace(arrPrograms(intProgram + 1), "%PROGRAMFILES%", oShell.ExpandEnvironmentStrings("%PROGRAMFILES%"))
    		strFileName2 = Replace(arrPrograms(intProgram + 1), "%PROGRAMFILES%", oShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%"))
    		If objFSO.FileExists(strFileName1) = False And objFSO.FileExists(strFileName2) = False Then
    			blnNeedsInstalling = True
    			WScript.Echo strProgramName & " is already installed."
    		End If
    	End If
    	If blnNeedsInstalling = True Then
    		intInstallCount = intInstallCount + 1
    		If intInstallCount = 1 Then
    			strProgramsToInstall = strProgramName
    			strInstallCommands = strProgramCommand
    			strProgramsToInstall = strProgramsToInstall & "|" & strProgramName
    			strInstallCommands = strProgramCommand & "|" & strProgramCommand
    		End If
    	End If
    If intInstallCount > 0 Then
    	WScript.Echo "The following " & intInstallCount & " programs are about to be installed:" & vbCrLf & Replace(strProgramsToInstall, "|", vbCrLf)
    	For Each strCommand In Split(strInstallCommands, "|")
    		oShell.Run strCommand, 1, True
    	WScript.Echo "No programs need installing."
    End If
    Function GetOSArchitecture(objRemote)
    	' TITLE: GetOSArchitecture
    	' DESCRIPTION: This function will use a WMI query to determine the system
    	'	architecture of the target computer
    	' INPUT:
    	'	objRemote must be an object that is bound to the WMI service on the target machine
    	'	Make a call such as Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    	'	and pass objWMI to this function
    	' OUTPUT:
    	'	A string value being 32 or 64
    	Set colOS = objRemote.ExecQuery("SELECT OSArchitecture FROM Win32_OperatingSystem",, 48) 
        For Each objOS In colOS 
            intAddressWidth = objOS.OSArchitecture
        If intAddressWidth = "32-bit" Then intAddressWidth = 32
        If intAddressWidth = "64-bit" Then intAddressWidth = 64
        GetOSArchitecture = intAddressWidth
    End Function 

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
    I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now