dim $strServerLocatorPoint,$strSiteCode,$strSMSInstall,$strSMSLogText,$strComputer,$strSMSClient,$errReturnCode
$strServerLocatorpoint = "servername"
$strSiteCode = "sitecode"
$strSMSInstall = "NO"
$strSMSLogText = ""
$strComputer = "."
$strSMSClient = ""
$errReturnCode = ""
;'Read WMI to get state of SMS client
;'------------------------------------
;'
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$SMSService = $objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = 'SMS Agent Host' ")
SMSServiceCheck
If $errReturnCode <> "0"
SMSInstallCheck
If $strSMSInstall = "YES"
SMSInstall
endif
Else
$SMSService = $objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = 'SMS Remote Control Agent' ")
SMSServiceCheck
EndIf
quit 0
;'*********************************
;'*Subroutines & Functions follow *
;'*********************************
Function SMSServiceCheck
;'------------------
$errReturnCode = "99"
For Each $objService in $SMSService
If $objService.State <> "Running"
$errReturnCode = $objService.Change( , , , , "Automatic")
$errReturnCode = $objService.StartService()
$strSMSLogText = $objService.Displayname + " restarted from Login Script"
SMSLogEvent
else
$errReturnCode = $objService.Change( , , , , "Automatic")
endif
Next
End function
Function SMSInstall
;'-------------
$strSMSClient = "\\" + $strServerLocatorPoint + "\SMSClient\i386\CAPINST.EXE /SLP=" +
$strServerLocatorPoint + " /ADVCLI /ADVCLICMD SMSSITECODE=" + strSiteCode
Set $objShell = CreateObject("WScript.Shell")
$objShell.Run $strSMSClient
$strSMSLogText = "SMS Client installed from Login Script"
SMSLogEvent
End Function
Function SMSLogEvent
;'--------------
dim $EVENT_SUCCESS,$objShell
$EVENT_SUCCESS = 4
$objShell = $CreateObject("wscript.Shell")
$objShell.LogEvent($EVENT_SUCCESS, $strSMSLogText)
$strSMSLogText = ""
End Sub
Function SMSInstallCheck
;'-----------------------
dim $HKEY_LOCAL_MACHINE
$HKEY_LOCAL_MACHINE = &H80000002
$strSMSInstall = "NO"
$strSMSServer = "0"
$strSMSProductSuite = ""
$strSMSType = ""
$strSMSVersion = ""
$strMIPSvalue = ""
$strComputer = "."
;Lets make sure we only install on WS with no security exceptions
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
$colOperatingSystems = $objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")
For Each $objOperatingSystem in $colOperatingSystems
$strSMSServer = InStr($objOperatingSystem.Caption, "Server")
$strSMSProductSuite = $objOperatingSystem.OSProductSuite
$strSMSType = $objOperatingSystem.OSType
$strSMSVersion = Left($objOperatingSystem.Version, 1)
Next
;Check for security Exclusion
$objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\default:StdRegProv")
$strKeyPath = "SOFTWARE\CSC\EDM\SMS\ClientConfig\Exclusions\MIPS"
$strEntryName = "ExclusionID"
$objReg.GetStringValue($HKEY_LOCAL_MACHINE,$strKeyPath,$strEntryName,$strMIPSValue)
;Lets work out if we should install a new client
If $strSMSServer <> "0" or $strSMSProductSuite <> "" or $strSMSType <> "18" or $strSMSVersion = "4" or $strMIPSValue <> "" then
$strSMSInstall = "NO"
else
$strSMSInstall = "YES"
EndIf
End Function