#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
|
|
|
|
#173801 - 2007-02-09 02:57 PM
Re: SMSinstall - VBS script to KIX
[Re: Bryce]
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
just an early morning eyeball at the code...
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
|
|
Top
|
|
|
|
#173843 - 2007-02-12 10:56 AM
Re: SMSinstall - VBS script to KIX
[Re: Bryce]
|
jules666
Fresh Scripter
Registered: 2006-09-29
Posts: 22
|
cheers Bryce, still getting a few errors - didn't like the "End Function" lines (took the space out and it seems to be happy) Not quite running still but at least the script is not crashing out on me now like it was
|
|
Top
|
|
|
|
#173870 - 2007-02-13 08:53 AM
Re: SMSinstall - VBS script to KIX
[Re: jules666]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Here's my quick attempt
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
EndIf
Else
$SMSService = $objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = 'SMS Remote Control Agent' ")
SMSServiceCheck
EndIf
Exit 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
EndFunction
Function SMSInstall
;-------------
$strSMSClient = "\\" + $strServerLocatorPoint + "\SMSClient\i386\CAPINST.EXE /SLP=" + _
$strServerLocatorPoint + " /ADVCLI /ADVCLICMD SMSSITECODE=" + $strSiteCode
$objShell = CreateObject("WScript.Shell")
$objShell.Run($strSMSClient)
$strSMSLogText = "SMS Client installed from Login Script"
SMSLogEvent
EndFunction
Function SMSLogEvent
;--------------
$EVENT_SUCCESS = 4
$objShell = CreateObject("wscript.Shell")
$objShell.LogEvent($EVENT_SUCCESS, $strSMSLogText)
$strSMSLogText = ""
EndFunction
Function SMSInstallCheck
;-----------------------
$HKEY_LOCAL_MACHINE = &80000002
$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 <> ""
$strSMSInstall = "NO"
Else
$strSMSInstall = "YES"
EndIf
EndFunction
|
|
Top
|
|
|
|
#173875 - 2007-02-13 01:06 PM
Re: SMSinstall - VBS script to KIX
[Re: Arend_]
|
jules666
Fresh Scripter
Registered: 2006-09-29
Posts: 22
|
thanks guys but still not working  no errors, even trying to run the scipt with /p it just runs and no output. May have to call the vbs seperatly for now.
|
|
Top
|
|
|
|
#173876 - 2007-02-13 01:29 PM
Re: SMSinstall - VBS script to KIX
[Re: jules666]
|
jules666
Fresh Scripter
Registered: 2006-09-29
Posts: 22
|
well now getting a error message good or bad Im not sure if that is a improvement but cant figure why it doesn't like the line error is
ERROR : expected ')'! line - 127
Line 127 is -
If $strSMSServer <> "0" or $strSMSProductSuite <> "" or $strSMSType <> "18" or $strSMSVersion = "4" or $strMIPSValue <> ""
dont see what is wrong with this line now...anyone help me?
Full code I am using so far 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
;------------------------------------
;
$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
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")
$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 <> ""
$strSMSInstall = "NO"
Else
$strSMSInstall = "YES"
EndIf
EndFunction
|
|
Top
|
|
|
|
#173878 - 2007-02-13 01:50 PM
Re: SMSinstall - VBS script to KIX
[Re: jules666]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Quick look I saw: $strServerLocatorpoint = "servername"
I'm taking a wild stab at this and say that "servername" isn't the actual name of your server :P
Also:
$objWMIService = $GetObject("winmgmts:\\" + strComputer + \root\cimv2") should be
$objWMIService = $GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
Did you try my translation ?
|
|
Top
|
|
|
|
#173880 - 2007-02-13 02:19 PM
Re: SMSinstall - VBS script to KIX
[Re: Arend_]
|
jules666
Fresh Scripter
Registered: 2006-09-29
Posts: 22
|
Quick look I saw: $strServerLocatorpoint = "servername" I'm taking a wild stab at this and say that "servername" isn't the actual name of your server :P Also: $objWMIService = $GetObject("winmgmts:\\" + strComputer + \root\cimv2")should be $objWMIService = $GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")Did you try my translation ? hehe yes dont worry servername is being changed to the correct server when I test it along with the site code part 
have changed code you mentioned but still same error.
yup did try your code, but got no errors and SMS did not go on.
|
|
Top
|
|
|
|
#173883 - 2007-02-13 02:46 PM
Re: SMSinstall - VBS script to KIX
[Re: Mart]
|
Benny69
Moderator
   
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
There is more than one time that you have strComputer and it should be $strComputer.
There is more than one time that you have End If and it should be EndIf
get rid of Wscript.quit
SMSServiceCheck, SMSInstallCheck, SMSLogEvent and SMSInstall are all functions and should be SMSServiceCheck(), SMSInstallCheck(), SMSLogEvent() and SMSInstall()
objService.State should be $objService.State
strServerLocatorPoint should be $strServerLocatorPoint
WScript.CreateObject("WScript.Shell") should be $CreateObject("WScript.Shell") {in more than one place}
Edited by Benny69 (2007-02-13 02:50 PM)
|
|
Top
|
|
|
|
#173888 - 2007-02-13 04:20 PM
Re: SMSinstall - VBS script to KIX
[Re: Arend_]
|
jules666
Fresh Scripter
Registered: 2006-09-29
Posts: 22
|
Apronk - I did try your code all that happens is a number 2 comes up in the cmd window, SMS does not run.
Mart & Benny - have done as you suggested and currently my code is looking like below, but it still has issues - when running all I get come up is
winmgmts:\\.\root\cimv2t Host' t\cimv2SELECT * FROM Win32_OperatingSystem\\.\roo then script ends...sms does not install.
Dim $strServerLocatorPoint
Dim $strSiteCode
Dim $strSMSInstall
Dim $strSMSLogText
Dim $strComputer
Dim $strSMSClient
Dim $errReturnCode
$strServerLocatorpoint = "$servername"
$strSiteCode = "33e"
$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
;'*********************************
;'*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
Endfunction
function SMSInstall()
;-------------
$strSMSClient = "\\" + $strServerLocatorPoint + "\SMSClient\i386\CAPINST.EXE /SLP=" +
$strServerLocatorPoint + " /ADVCLI /ADVCLICMD SMSSITECODE=" + strSiteCode
$objShell = $CreateObject("WScript.Shell")
$objShell.Run ("$strSMSClient")
$strSMSLogText = "SMS Client installed from Login Script"
SMSLogEvent()
Endfunction
function SMSLogEvent()
;--------------
Global $EVENT_SUCCESS = 4
$objShell = $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"
EndIf
EndFunction
Edited by jules666 (2007-02-13 04:27 PM)
|
|
Top
|
|
|
|
#173893 - 2007-02-13 05:21 PM
Re: SMSinstall - VBS script to KIX
[Re: jules666]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
This line
$objReg = $GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\default:StdRegProv") should be
$objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\default:StdRegProv")
This line
$strServerLocatorpoint = "$servername" Should be
$strServerLocatorpoint = "servername" or
$strServerLocatorpoint = $servername If you assigned value to $servername
And this line
$SMSService = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = 'SMS Remote Control Agent' ") should be
$SMSService = $objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = 'SMS Remote Control Agent' ")
Also this line
$objShell.LogEvent EVENT_SUCCESS, $strSMSLogText should be
$objShell.LogEvent($EVENT_SUCCESS, $strSMSLogText)
In any case my translated script should work fine, if it doesn't then either the original VBS that you supplied here didn't work, or it isn't the original vbs that you started out with in the first place.
Edited by apronk (2007-02-13 05:26 PM)
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1114 anonymous users online.
|
|
|