• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

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."
  Else 
oShell.Run "RunAs /user:admin@mydomain ""\\192.168.1.5\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.
TM
0
Thomas_Meyer
Asked:
Thomas_Meyer
1 Solution
 
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 ninite.com if these are standard type apps?  It will build an installer to silently install /reply update whatever you ask it to.

Steve
0
 
RobSampsonCommented:
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

Regards,

Rob.

Dim objFSO, oShell

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
strArchitecture = GetOSArchitecture(objWMIService)

' Add your programs here, in lots of three elements
' ie, NAME, EXE PATH TO TEST FOR, INSTALLATION COMMAND
' 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 ""\\192.168.1.5\i$\INSTALL\GIMP\gimp-2.8.2-setup-1.exe /SILENT /NOCANCEL /NORESTART""", _
	"WinZip 10", "", "%PROGRAMFILES%\Winzip\Winzip.exe", "RunAs /user:admin@mydomain ""\\192.168.1.5\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
		Else
			WScript.Echo strProgramName & " is already installed."
		End If
	Else
		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
		Else
			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
		Else
			strProgramsToInstall = strProgramsToInstall & "|" & strProgramName
			strInstallCommands = strProgramCommand & "|" & strProgramCommand
		End If
	End If
	
Next

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
	Next
Else
	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
    Next
    If intAddressWidth = "32-bit" Then intAddressWidth = 32
    If intAddressWidth = "64-bit" Then intAddressWidth = 64
    GetOSArchitecture = intAddressWidth
End Function 

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now