#173788 - 2007-02-09 10:03 AM
SMSinstall - VBS script to KIX
|
jules666
Fresh Scripter
Registered: 2006-09-29
Posts: 22
|
Hi
Been trying to convert a vbs script into kix. This script installs SMS based on some hard coded variables (server,site code which I will change eventually to user inputed variables) I have tried to use the vbs2kix udf, but it did not seem to do it right. So have manaully had a go, could someone take a look at try help me with where I have gone wrong?.. I'am pretty new to coding in general so sorry if I don't understand anything you all say , but have been asked to come up with a script to run after we have installed the companys default image on a machine, normally the logon script runs the vbs code fine and sms goes on ok, but we are thinking about when machines are used by users from different OU's whose logon script does not install SMS (yes unfortunatly a global logon script is a long way away!)
EDIT - Just to add, want to convert it to KIX as I have a larger script that does a few config settings/SAV setup on the newly built machine, and I want to include the SMS install as part of that, if it becomes too much then I suppose I could call the .vbs script on its own, but would then need to know how to have the original KIX script send some use inputed variables, sms server/site code into the vbs file.
VBS script is -
dim strServerLocatorPoint
dim strSiteCode
dim strSMSInstall
dim strSMSLogText
dim strComputer
dim strSMSClient
dim errReturnCode
strServerLocatorpoint = "servername"
strSiteCode = "sitecode"
strSMSInstall = "NO"
strSMSLogText = ""
strComputer = "."
strSMSClient = ""
errReturnCode = ""
'Read WMI to get state of SMS client
'------------------------------------
'
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set SMSService = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = 'SMS Agent Host' ")
SMSServiceCheck
If errReturnCode <> "0" then
SMSInstallCheck
If strSMSInstall = "YES" then
SMSInstall
end if
Else
Set SMSService = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = 'SMS Remote Control Agent' ")
SMSServiceCheck
End If
Wscript.quit
'*********************************
'*Subroutines & Functions follow *
'*********************************
Sub SMSServiceCheck
'------------------
errReturnCode = "99"
For Each objService in SMSService
If objService.State <> "Running" then
errReturnCode = objService.Change( , , , , "Automatic")
errReturnCode = objService.StartService()
strSMSLogText = objService.Displayname & " restarted from Login Script"
SMSLogEvent
else
errReturnCode = objService.Change( , , , , "Automatic")
end if
Next
End Sub
Sub SMSInstall
'-------------
strSMSClient = "\\" & strServerLocatorPoint & "\SMSClient\i386\CAPINST.EXE /SLP=" & _
strServerLocatorPoint & " /ADVCLI /ADVCLICMD SMSSITECODE=" & strSiteCode
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run strSMSClient
strSMSLogText = "SMS Client installed from Login Script"
SMSLogEvent
End Sub
Sub SMSLogEvent
'--------------
Const EVENT_SUCCESS = 4
Set objShell = wscript.CreateObject("wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, strSMSLogText
strSMSLogText = ""
End Sub
Function SMSInstallCheck
'-----------------------
Const 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
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set 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
Set 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"
End If
End Function
my kix attempt so far....
Dim $strServerLocatorPoint
Dim $strSiteCode
Dim $strSMSInstall
Dim $strSMSLogText
Dim $strComputer
Dim $strSMSClient
Dim $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
end if
Else
$SMSService = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = 'SMS Remote Control Agent' ")
SMSServiceCheck
End If
Wscript.quit
;'*********************************
;'*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")
end if
Next
Endfunction
function SMSInstall()
;-------------
$strSMSClient = "\\" + strServerLocatorPoint + "\SMSClient\i386\CAPINST.EXE /SLP=" +
$strServerLocatorPoint + " /ADVCLI /ADVCLICMD SMSSITECODE=" + strSiteCode
$objShell = WScript.CreateObject("WScript.Shell")
objShell.Run strSMSClient
$strSMSLogText = "SMS Client installed from Login Script"
SMSLogEvent
Endfunction
function SMSLogEvent()
;--------------
Global $EVENT_SUCCESS = 4
$objShell = wscript.CreateObject("wscript.Shell")
$objShell.LogEvent EVENT_SUCCESS, strSMSLogText
$strSMSLogText = ""
Endfunction
Function SMSInstallCheck()
;-----------------------
$HKEY_LOCAL_MACHINE = "+H80000002"
$strSMSInstall = "NO"
$strSMSServer = "0"
$strSMSProductSuite = ""
$strSMSType = ""
$strSMSVersion = ""
$strMIPSvalue = ""
$strComputer = "."
;Lets make sure we only install on WS with no MIPS 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 MIPS 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 <> ""
$strSMSInstall = "NO"
else
$strSMSInstall = "YES"
End If
EndFunction
Edited by jules666 (2007-02-09 11:37 AM)
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(mole)
and 1441 anonymous users online.
|
|
|