' Declare Constants
const HKEY_LOCAL_MACHINE = &H80000002 ' HKEY LOCALMACHINE
Const conFileExistPath = "\Altiris\Altiris Agent\" ' Install Path of Altiris Agent
Const conFileName = "AeXNSAgent.exe" ' Agent Executable to check for existance
Const conPackageLocation = "\\hqdc01.thenetworkguru.local\NETLOGON\AeXNSC.exe" ' Location to Altiris Install
Const conInstallPath = "\AeXNSC.exe -s -a ns=""hqns01.thenetworkguru.local"" NOSTARTMENU NOTRAYICON /s /NOADDREMOVE"' Altiris NS Agent Install Command Line
Const conRedirectPathFileName = "AeXAgentUtil.exe" ' File to Redirect Altiris Agent
Const conCMDOptions = "/server:hqns01.thenetworkguru.local /web:http://hqns01.thenetworkguru.local/Altiris" ' Options to Redirect Altiris Agent
Const conKeyPath = "SOFTWARE\Altiris\Altiris Agent\Servers" ' Reg Path to Altiris Server
Const conKeyPath64 = "SOFTWARE\Wow6432Node\Altiris\Altiris Agent\Servers" ' x64 Reg Path to Altiris Server
Const conKeyName = "" ' Reg Value to find, blank = (default)
Const conServerName = "hqns01.thenetworkguru.local" ' Altiris NS Server Name
Const conPSExecLoc = "\\thenetworkguru.local\NETLOGON\psexec.exe" ' Path to PSEXEC for Win Vista/7
' Declare Variables
Dim strComputer ' Computer to connect to WMI Server
Dim objWMIService ' Object to connect to WMI Service
Dim osShell ' Shell object to get environmental variables
Dim oReg ' Registry object to get current NS Server setting
Dim colItems ' Array of Win32_ComputerSystem Objects
Dim objItem ' Single instance of Win32_ComputerSystem from above variable
Dim strSystemType ' Type of system x86 or x64
Dim strRootDrive ' Root drive of current system
Dim strProgramFilesPath ' Path to Altiris Agent Program Files Directory
Dim strFullPath ' Full Path to AeXNSAgent.exe file
Dim strRedirectPath ' Full Path to AeXAGEntUtil executable along with command line options
Dim objFileSys ' File System Object used to check for file existenance
Dim objFSO ' File System Object used to get file version
Dim objFileVersion ' File Version of current AeXNSAgent.exe
Dim strRC ' Return Code for Run method
Dim strServerValue ' Notification Server Name from registry
Dim colOSItems ' Collection Of Operating System Detail Items
Dim objOSItem ' Individual OS Item
Dim strOSVersion ' Windows Version
' Create Shell to get Environmental Variables
Set osShell = CreateObject("WScript.Shell")
' Create WMI Connection to local computer
strComputer = "."
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
' Get System Architecture Type
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem in colItems
strSystemType = objItem.SystemType
Next
' Get System Root Environment Variable
strRootDrive = osShell.ExpandEnvironmentStrings("%SystemRoot%")
' Based on System Type, Get Correct Program Files Folder
If (strSystemType = "X86-based PC") Then
' Get program files path
strProgramFilesPath = osShell.ExpandEnvironmentStrings("%Programfiles%")
Else
strProgramFilesPath = osShell.ExpandEnvironmentStrings("%Programfiles(x86)%")
End If
' Create Path to Current Altiris Agent AeXNSAgent.exe File
strFullPath = strProgramFilesPath & conFileExistPath & conFileName
' Check for AeXNSAgent.exe File Existenance
Set objFileSys = CreateObject("Scripting.FileSystemObject")
If objFileSys.FileExists(strFullPath) Then
' Get File Properties
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFileVersion = objFSO.GetFileVersion(strFullPath)
' Create Full Command Line to Redirect Altiris Agent
strRedirectPath = Chr(34) & strProgramFilesPath & conFileExistPath & conRedirectPathFileName & Chr(34) & " " & conCMDOptions
' Check File Version, If Version 6 upgrade, otherwise check server name
If Left(objFileVersion,1) = 6 Then
' Old Agent, Upgrade, Start by coping file to local harddrive:\Windows
Dim objCopyFile
Set objCopyFile = CreateObject("Scripting.FileSystemObject")
objCopyFile.CopyFile conPackageLocation, strRootDrive & "\AeXNSC.exe"
' Check Operating System Version
Set colOSItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)
For Each objOSItem in colOSItems
strOSVersion = objOSItem.Version
Next
If Left(strOSVersion,1) = 6 Then
' Run using PSEXEC
strRC = osShell.Run ("cmd /c " & conPSExecLoc & " /accepteula -s " & strRootDrive & conInstallPath, 0, true)
Else
' Run Normally
strRC = osShell.Run ("cmd /c " & strRootDrive & conInstallPath, 0, true)
End If
Else
' Version 7 Agent, Check Server Name Registry Key
If (strSystemType = "X86-based PC") Then
oReg.GetStringValue HKEY_LOCAL_MACHINE, conKeyPath, conKeyName, strServerValue
Else
oReg.GetStringValue HKEY_LOCAL_MACHINE, conKeyPath64, conKeyName, strServerValue
End If
' Verify Server Name, if not our server, redirect Agent
If (strServerValue <> conServerName) Then
' Check Operating System Version
Set colOSItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)
For Each objOSItem in colOSItems
strOSVersion = objOSItem.Version
Next
If Left(strOSVersion,1) = 6 Then
' Run using PSEXEC
strRC = osShell.Run ("cmd /c " & conPSExecLoc & " /accepteula -s " & strRedirectPath, 0, true)
Else
' Run Normally
strRC = osShell.Run ("cmd /c " & strRedirectPath, 0, true)
End If
End If
End If
Else
' No Agent, Install, first by copying AeXNSC.exe file to localdrive:\Windows
Dim objCopyFile1
Set objCopyFile1 = CreateObject("Scripting.FileSystemObject")
objCopyFile1.CopyFile conPackageLocation, strRootDrive & "\AeXNSC.exe"
' Check Operating System Version
Set colOSItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)
For Each objOSItem in colOSItems
strOSVersion = objOSItem.Version
Next
If Left(strOSVersion,1) = 6 Then
' Run using PSEXEC
strRC = osShell.Run ("cmd /c " & conPSExecLoc & " /accepteula -s " & strRootDrive & conInstallPath, 0, true)
Else
' Run Normally
strRC = osShell.Run ("cmd /c " & strRootDrive & conInstallPath, 0, true)
End If
End If
|