Page 1 of 1 1
Topic Options
#173788 - 2007-02-09 10:03 AM SMSinstall - VBS script to KIX
jules666 Offline
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 -
 Code:
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....

 Code:
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
#173799 - 2007-02-09 02:37 PM Re: SMSinstall - VBS script to KIX [Re: jules666]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If strSMSInstall = "YES"
is missing the $
If $strSMSInstall = "YES"
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#173800 - 2007-02-09 02:56 PM Re: SMSinstall - VBS script to KIX [Re: Les]
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
missing a lot of $....
Top
#173801 - 2007-02-09 02:57 PM Re: SMSinstall - VBS script to KIX [Re: Bryce]
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
just an early morning eyeball at the code...

 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 Offline
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_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Here's my quick attempt
 Code:
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 Offline
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 Offline
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 -
 Code:
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 -

 Code:
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_ Moderator Offline
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:
 Code:
$objWMIService = $GetObject("winmgmts:\\" + strComputer + \root\cimv2")

should be
 Code:
$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 Offline
Fresh Scripter

Registered: 2006-09-29
Posts: 22
 Originally Posted By: apronk
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:
 Code:
$objWMIService = $GetObject("winmgmts:\\" + strComputer + \root\cimv2")

should be
 Code:
$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
#173881 - 2007-02-13 02:29 PM Re: SMSinstall - VBS script to KIX [Re: jules666]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You should also remove the space from both endif's in this part of the script.

 Code:
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
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#173883 - 2007-02-13 02:46 PM Re: SMSinstall - VBS script to KIX [Re: Mart]
Benny69 Offline
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)
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#173884 - 2007-02-13 02:54 PM Re: SMSinstall - VBS script to KIX [Re: Benny69]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Try my complete translated code and tell me where and what errors you get.
Top
#173888 - 2007-02-13 04:20 PM Re: SMSinstall - VBS script to KIX [Re: Arend_]
jules666 Offline
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

 Quote:
winmgmts:\\.\root\cimv2t Host' t\cimv2SELECT * FROM Win32_OperatingSystem\\.\roo

then script ends...sms does not install.
 Code:
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_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
This line
 Code:
$objReg = $GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\default:StdRegProv")

should be
 Code:
$objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\default:StdRegProv")


This line
 Code:
$strServerLocatorpoint = "$servername"

Should be
 Code:
$strServerLocatorpoint = "servername"

or
 Code:
$strServerLocatorpoint = $servername
If you assigned value to $servername

And this line
 Code:
$SMSService = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = 'SMS Remote Control Agent' ")

should be
 Code:
$SMSService = $objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName = 'SMS Remote Control Agent' ")


Also this line
 Code:
$objShell.LogEvent EVENT_SUCCESS, $strSMSLogText

should be
 Code:
$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
#173899 - 2007-02-14 10:34 AM Re: SMSinstall - VBS script to KIX [Re: Arend_]
jules666 Offline
Fresh Scripter

Registered: 2006-09-29
Posts: 22
 Originally Posted By: apronk

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.

ok m8 went back to trying yours again, still just get the number 2 come up in console - the vbs script works fine no issues and I double checked my first post and I copied the code exactly.

No idea why this is failing in KIX...shame I may have to call the VBS script seperatly then \:\(

Top
#173935 - 2007-02-15 11:18 AM Re: SMSinstall - VBS script to KIX [Re: jules666]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
You should value check $errReturnCode right after SMSInstallCheck see what value that gives you. It might get wrong from there.

Also do some @error checks in the script see where you get a value higher then 0. That way you can pinpoint where it goes wrong.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1017 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.125 seconds in which 0.093 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org