How gradually to install programs using vb script?

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.
Who is Participating?
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
	'	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
	'	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

Steve KnightIT ConsultancyCommented:
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.