VBScript to automaticly install and config snmp

To the Ipswitch web site

Ipswitch Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



VBScript to automaticly install and config snmpExpand / Collapse
Author
Message
Posted 10/8/2008 2:41:49 AM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 12/29/2008 5:26:20 AM
Posts: 14, Visits: 22
Hello there,

as a fool it-networker, i've written a VBScript which checks automaticly if the snmp service is installed or not. If yes it just configure it, if not it first install the snmp service from a network i386 source and then configure it. I know the script is written not so well but please feel free to modify or update it...

ok here it goes (Copy the script into a texteditor and save it as nameofthescript.vbs):

' *************************************************************************************
' Beschreibung: Script zur automatischen Installation und Konfiguration des SNMP
' Services auf den Servern Rechnern welche durch WU überwacht werden
' sollen.
'
' erstellt am: 01.03.2008
' Copyright: Key Net AG
' Author: Reto Bösch
' Version: 1.0
' geändert am:-
' *************************************************************************************


'Variablen deklarieren

'Konstante definieren
Const HKEY_LOCAL_MACHINE = &H80000002

'Lokaler Computer wird verwendet
strComputer = "."

'Definition der neuen SNMP Communities
SNMPRead = "key_net"
' *** remarked da nur read gesetzt wird
' SNMPWrite = "SNMPReadandWriteCommunity"

'Definition des neuen SNMP Host
SNMPHost = "192.168.254.70"

'SNMP bereits installiert
isnmp = 0

'Prüfe ob SNMP bereits auf dem Rechner installiert ist

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service")

strServiceName = "snmp"

If Not IsNull(colServiceList) Then
For Each objService In colServiceList
If LCase(strServiceName) = LCase(objService.Name) Then
isnmp = 1
End If
Next
End If

If isnmp = 1 Then
'snmp konfigurieren
confSNMP

Else
'********************************************************************************************************
'snmp installieren & konfigurieren

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

'Snmp unattendet Text Datei erstellen
Set uaFile = objFSO.CreateTextFile("c:\snmp.ua",True)
uaFile.Writeline "[NetOptionalComponents]"
uaFile.Writeline "SNMP = 1"
uaFile.Close

os = determineOperatingSystem(strComputer)
sp = determineServicePack(strComputer)
WScript.Echo ("Will add SNMP files for " & os & " with service pack " & sp)
editServerRegistry strComputer, os, sp
RunRmtProcess "snmp"
WScript.Sleep 120000
confSNMP

Set objShell = Nothing
Set objFSO = Nothing
End If
WScript.quit



'******FUNCTION AND SUBROUTINES******

'Betriebssystem auslesen
Function determineOperatingSystem(server)
Set objWMIService = GetObject("winmgmts:\\" & server & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
determineOperatingSystem = objOperatingSystem.Caption
Next
End Function


'Service Pack auslesen
Function determineServicePack(server)
Set objWMIService = GetObject("winmgmts:\\" & server & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
determineServicePack = objOperatingSystem.ServicePackMajorVersion
Next
End Function


'Firewall Konfigurieren
Sub setFirewallSettings(srv,serverOS,spVer)
Select Case serverOS
Case "Microsoft Windows XP Professional"
Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
If objPolicy.FirewallEnabled = TRUE Then
Set objPort = CreateObject("HNetCfg.FwOpenPort")
objPort.Port = 161
objPort.Protocol = 17
objPort.Name = "SNMP"
objPort.Enabled = True
Set colPorts = objPolicy.GloballyOpenPorts
errReturn = colPorts.Add(objPort)
End If
Case "Microsoft Windows 2000 Server"
Case "Microsoft(R) Windows(R) Server 2003, Standard Edition"
Case Else
WScript.Echo ("Operating System is not Windows 2000 Server or Server 2003 Standard Edition. This script will now close!")
WScript.Quit
End Select
End Sub

Sub editServerRegistry(srv,serverOS,spVer)
Select Case serverOS
Case "Microsoft Windows XP Professional"
If spVer = 2 Then
i386Location = "\\knsrv01\kbase\Microsoft\Software\ClientOS\WinXP\I386\SP2"
Else
WScript.Echo("Service pack level is not at 2. This script will now close!")
WScript.Quit
End If
Case "Microsoft Windows 2000 Server"
If spVer = 3 Then
i386Location = "\\\path"
ElseIf spVer = 4 Then
i386Location = "\\\path"
Else
WScript.Echo("Service pack level is not at 3 or 4. This script will now close!")
WScript.Quit
End If

Case "Microsoft(R) Windows(R) Server 2003, Standard Edition"
If spVer = 1 Then
i386Location = "\\\path"
ElseIf spVer = 2 Then
i386Location = "\\\path"
Else
WScript.Echo("Service pack level is not at 1 or 2. This script will now close!")
WScript.Quit
End If
Case Else
WScript.Echo ("Operating System is not Windows 2000 Server or Server 2003 Standard Edition. This script will now close!")
WScript.Quit
End Select

'GET CURRENT REGISTRY VALUES SO THEY MAY BE SAVED
Set objRegistry=GetObject("winmgmts:\\" & srv & "\root\default:StdRegProv")
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","SourcePath",oldRegVal1
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","ServicePackSourcePath",oldRegVal2
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","SourcePath",oldRegVal3

If oldRegVal1 <> i386Location Then
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","SourcePath",i386Location
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","SourcePath.old",oldRegVal1
End If

If oldRegVal2 <> i386Location Then
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","ServicePackSourcePath",i386Location
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","ServicePackSourcePath.old",oldRegVal2
End If

If oldRegVal3 <> i386Location Then
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","SourcePath",i386Location
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","SourcePath.old",oldRegVal3
End If
End Sub


Sub RunRmtProcess(process)

'SNMP INSTALLATION
If process="snmp" Then
objShell.run "sysocmgr /i:%windir%\inf\sysoc.inf /u:c:\snmp.ua /x /q /r", vbHide
End If
End Sub


'snmp konfigurieren
Sub confSNMP()

'Bestehende SNMP Hosts auslesen

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\PermittedManagers"

oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_
arrValueNames, arrValueTypes

If Not IsNull(arrValueNames) Then
For i=0 To UBound(arrValueNames)
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames(i),strValue

'Bestehende SNMP Hosts löschen
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames(i)
Next
End If

'Neuer SNMP Host hinzufügen
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,i+1,SNMPHost

'Objekte auf Null setzen
strKeyPath=Null
arrValueNames=Null
arrValueTypes=Null


'Bereits definierte SNMP Communities auslesen

strKeyPath = "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities"

oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_
arrValueNames, arrValueTypes

If Not IsNull(arrValueNames) Then
For i=0 To UBound(arrValueNames)
oReg.GetDWordValue HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames(i),dwValue

'SNMP Communities löschen
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames(i)
Next
End If

'SNMP Communities setzen
oReg.SetDwordValue HKEY_LOCAL_MACHINE,strKeyPath,SNMPRead,4
' *** remarked da nur read gesetzt wird
' oReg.SetDwordValue HKEY_LOCAL_MACHINE,strKeyPath,SNMPWrite,8

'SNMP Service auf automatisch und starten

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name='SNMP'")

If Not IsNull(colServiceList) Then

For Each objService In colServiceList

WScript.Echo objService.StartMode

StartMode = UCase(objService.StartMode)

If (StartMode = "MANUAL") Or (StartMode = "DISABLED") Then
errReturnCode = objService.ChangeStartMode("Auto")
End If
errReturnCode = objService.StartService()
Next
End If

'Objekte auf Null setzten
colServiceList = Null
objService = Null
objWMIService = Null

'SNMP-Traps Service deaktivieren und stoppen

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name='SNMPTRAP'")

If Not IsNull(colServiceList) Then

For Each objService In colServiceList

StartMode = UCase(objService.StartMode)

If (StartMode = "MANUAL") Or (StartMode = "AUTO") Then
errReturnCode = objService.ChangeStartMode("Disabled")
errReturnCode = objService.StopService()
End If
Next
End If

'Objekte auf Null setzten
colServiceList = Null
objService = Null
objWMIService = Null

'Firewall konfigurieren
os = determineOperatingSystem(strComputer)
sp = determineServicePack(strComputer)
setFirewallSettings strComputer, os, sp


End Sub

















Post #47580
Posted 12/4/2008 10:04:43 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 12/5/2008 9:50:51 AM
Posts: 1, Visits: 2
I have do some changes.
- add support for xp sp3
- add support for windows server 2003 enterprise
- some little changes with output an variables

thx for the script.

edit: IFCode "code" sucks, script attached as txt file .. rename to vbs

' *************************************************************************************
' * Beschreibung: Script zur automatischen Installation und Konfiguration des SNMP
' * Services auf den Servern Rechnern welche durch WU überwacht werden
' * sollen.
' *
' * erstellt am: 01.03.2008
' * Copyright: Key Net AG
' * Author: Reto Bösch
' * Version: 1.1
' * geändert am: 2008-12-04
' *
' * changes
' * - support Windows XP Professional SP3
' * - support Microsoft(R) Windows(R) Server 2003 Enterprise Edition
' * - some litte changes
' *
' *************************************************************************************

' *************************************************************************************
' * your personalization
' *************************************************************************************

'constant
Const HKEY_LOCAL_MACHINE = &H80000002

'computer on which SNMP service should installed
' "." is the local computer
strComputer = "."

'define snmp read community string
SNMPRead = "public"

'define snmp read/write community string
'if you don't need it, set enableReadWrite = false
enableReadWrite = false
If enableReadWrite Then
SNMPWrite = "securedpass"
End If

'new SNMP host
SNMPHost = "10.10.10.10"

'SNMP allready installed
isnmp = 0

'source path
'Microsoft(R) Windows(R) Server 2003, Standard Edition (SP1/SP2)
osSourcePathWinSer2003StdSPI = "\\path\to\windows\source\"
osSourcePathWinSer2003StdSPII = "\\path\to\windows\source\"
'Microsoft(R) Windows(R) Server 2003 Enterprise Edition (SP1/SP2)
osSourcePathWinSer2003EntSPI = "\\path\to\windows\source\"
osSourcePathWinSer2003EntSPII = "\\path\to\windows\source\"
'"Microsoft Windows 2000 Server (SP3/SP4)"
osSourcePathWinSer2000SPIII = "\\path\to\windows\source\"
osSourcePathWinSer2000SPIV = "\\path\to\windows\source\"
'Microsoft Windows XP Professional (SP2/SP3)
osSourcePathWinXPproSPII = "\\path\to\windows\source\"
osSourcePathWinXPproSPIII = "\\path\to\windows\source\"

'output flags (only for text output)
'info flag, can be turned of
infomode = true
'infomode = false

'debug flag, only for expand this script
'debugmode = true
debugmode = false

'error flag, should be turned on (true)
errormode = true
'errormode = false

If debugmode Then
debugFlagsString = "Debug modus ON"

If infomode Then
debugFlagsString = debugFlagsString & ", Info modus ON"
else
debugFlagsString = debugFlagsString & ", Info modus OFF"
End If
If errormode Then
debugFlagsString = debugFlagsString & ", Error modus ON"
else
debugFlagsString = debugFlagsString & ", Error modus OFF"
End If

WScript.Echo("[DEBUG] " & debugFlagsString)
End If

' *************************************************************************************
' * personalization ENDS, script code STARTS
' *************************************************************************************

'check SNMP service is installed
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service")

strServiceName = "snmp"

If Not IsNull(colServiceList) Then
For Each objService In colServiceList
If LCase(strServiceName) = LCase(objService.Name) Then
isnmp = 1
End If
Next
End If

If isnmp = 1 Then
If infomode Then
WScript.Echo("[INFO] SNMP service installed, start configuration.")
End If
'snmp service installed, only configuration needed
confSNMP
Else
If infomode Then
WScript.Echo("[INFO] SNMP service NOT installed, start installation and configuration")
End If
'********************************************************************************************************
'snmp service NOT installed, installation AND configuration needed

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

'snmp unattended text file created
Set uaFile = objFSO.CreateTextFile("c:\snmp.ua",True)
uaFile.Writeline "[NetOptionalComponents]"
uaFile.Writeline "SNMP = 1"
uaFile.Close

os = determineOperatingSystem(strComputer)
sp = determineServicePack(strComputer)
If infomode Then
WScript.Echo ("[INFO] Will add SNMP files for " & os & " with service pack " & sp)
End If
editServerRegistry strComputer, os, sp
RunRmtProcess "snmp"
WScript.Sleep 120000
confSNMP

Set objShell = Nothing
Set objFSO = Nothing
End If
WScript.quit

' *************************************************************************************
' * FUNCTION AND SUBROUTINES
' *************************************************************************************
'read operation system
Function determineOperatingSystem(server)
Set objWMIService = GetObject("winmgmts:\\" & server & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
determineOperatingSystem = objOperatingSystem.Caption
If debugmode Then
WScript.Echo ("[DEBUG] OS: " & determineOperatingSystem )
End If
Next
End Function

'read service pack number
Function determineServicePack(server)
Set objWMIService = GetObject("winmgmts:\\" & server & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
determineServicePack = objOperatingSystem.ServicePackMajorVersion
If debugmode Then
WScript.Echo ("[DEBUG] SP: " & determineServicePack )
End If

Next
End Function

'firewall configuration
Sub setFirewallSettings(srv,serverOS,spVer)
Select Case serverOS
Case "Microsoft Windows XP Professional"
Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
If objPolicy.FirewallEnabled = TRUE Then
Set objPort = CreateObject("HNetCfg.FwOpenPort")
objPort.Port = 161
objPort.Protocol = 17
objPort.Name = "SNMP"
objPort.Enabled = True
Set colPorts = objPolicy.GloballyOpenPorts
errReturn = colPorts.Add(objPort)
End If
Case "Microsoft Windows 2000 Server"
Case "Microsoft(R) Windows(R) Server 2003, Standard Edition"
Case "Microsoft(R) Windows(R) Server 2003 Enterprise Edition"
Case Else
If errormode Then
WScript.Echo ("[ERROR] Operating System is not Windows 2000 Server or Server 2003 Standard Edition. This script will now close!")
End If
WScript.Quit
End Select
End Sub

'change source path (in the regestry) to your path
Sub editServerRegistry(srv,serverOS,spVer)
Select Case serverOS
Case "Microsoft Windows XP Professional"
If spVer = 2 Then
i386Location = osSourcePathWinXPproSPII
ElseIf spVer = 3 Then
i386Location = osSourcePathWinXPproSPIII
Else
If errormode Then
WScript.Echo ("[ERROR] Service pack level is not at 2 or 3. This script will now close!")
End If
WScript.Quit
End If
Case "Microsoft Windows 2000 Server"
If spVer = 3 Then
i386Location = osSourcePathWinSer2000SPIII
ElseIf spVer = 4 Then
i386Location = osSourcePathWinSer2000SPIV
Else
If errormode Then
WScript.Echo ("[ERROR] Service pack level is not at 3 or 4. This script will now close!")
End If
WScript.Quit
End If
Case "Microsoft(R) Windows(R) Server 2003, Standard Edition"
If spVer = 1 Then
i386Location = osSourcePathWinSer2003StdSPI
ElseIf spVer = 2 Then
i386Location = osSourcePathWinSer2003StdSPII
Else
If errormode Then
WScript.Echo ("[ERROR] Service pack level is not at 1 or 2. This script will now close!")
End If
WScript.Quit
End If
Case "Microsoft(R) Windows(R) Server 2003 Enterprise Edition"
If spVer = 1 Then
i386Location = osSourcePathWinSer2003EntSPI
ElseIf spVer = 2 Then
i386Location = osSourcePathWinSer2003EntSPII
Else
If errormode Then
WScript.Echo ("[ERROR] Service pack level is not at 1 or 2. This script will now close!")
End If
WScript.Quit
End If
Case Else
If errormode Then
WScript.Echo ("[ERROR] Operating System (" & serverOS & ") is not supported. This script will now close!")
End If
WScript.Quit
End Select

'get current registry values and may be changed
Set objRegistry=GetObject("winmgmts:\\" & srv & "\root\default:StdRegProv")
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","SourcePath",oldRegVal1
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","ServicePackSourcePath",oldRegVal2
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","SourcePath",oldRegVal3

If oldRegVal1 <> i386Location Then
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","SourcePath",i386Location
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","SourcePath.old",oldRegVal1
End If

If oldRegVal2 <> i386Location Then
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","ServicePackSourcePath",i386Location
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","ServicePackSourcePath.old",oldRegVal2
End If

If oldRegVal3 <> i386Location Then
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","SourcePath",i386Location
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","SourcePath.old",oldRegVal3
End If
End Sub


Sub RunRmtProcess(process)
'snmp installation
If process="snmp" Then
objShell.run "sysocmgr /i:%windir%\inf\sysoc.inf /u:c:\snmp.ua /x /q /r", vbHide
End If
End Sub

'snmp configuration
Sub confSNMP()
'read current SNMP hosts
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\PermittedManagers"
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_
arrValueNames, arrValueTypes

If Not IsNull(arrValueNames) Then
For i=0 To UBound(arrValueNames)
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames(i),strValue
'clear current SNMP hosts
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames(i)
Next
End If

'add new SNMP host
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,i+1,SNMPHost

'clear objects
strKeyPath=Null
arrValueNames=Null
arrValueTypes=Null

'read current community string
strKeyPath = "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities"

oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_
arrValueNames, arrValueTypes

If Not IsNull(arrValueNames) Then
For i=0 To UBound(arrValueNames)
oReg.GetDWordValue HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames(i),dwValue
'SNMP clear community string
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames(i)
Next
End If

'SNMP read community string
oReg.SetDwordValue HKEY_LOCAL_MACHINE,strKeyPath,SNMPRead,4

'SNMP read/write community string
If enableReadWrite Then
oReg.SetDwordValue HKEY_LOCAL_MACHINE,strKeyPath,SNMPWrite,8
End If

'SNMP Service auf automatisch und starten
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name='SNMP'")


If Not IsNull(colServiceList) Then

For Each objService In colServiceList
If debugmode Then
WScript.Echo ("[DEBUG] ServiceStarmode(SNMP) = " & objService.StartMode )
End If
StartMode = UCase(objService.StartMode)
If (StartMode = "MANUAL") Or (StartMode = "DISABLED") Then
errReturnCode = objService.ChangeStartMode("Auto")
End If
errReturnCode = objService.StartService()
Next
End If

'clear objects
colServiceList = Null
objService = Null
objWMIService = Null

'SNMP-Traps service deactivate and stop
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name='SNMPTRAP'")

If Not IsNull(colServiceList) Then
For Each objService In colServiceList
If debugmode Then
WScript.Echo ("[DEBUG] ServiceStarmode(SNMPTRAP) = " & objService.StartMode )
End If
StartMode = UCase(objService.StartMode)
If (StartMode = "MANUAL") Or (StartMode = "AUTO") Then
errReturnCode = objService.ChangeStartMode("Disabled")
errReturnCode = objService.StopService()
End If
Next
End If

'clear objects
colServiceList = Null
objService = Null
objWMIService = Null

'firewall configuration
os = determineOperatingSystem(strComputer)
sp = determineServicePack(strComputer)
setFirewallSettings strComputer, os, sp

End Sub


  Post Attachments 
renametovbs.txt (5 views, 12.74 KB)
Post #49214
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Jason Benton, Jason Williams

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 8:48pm

Powered By InstantForum.NET v4.1.4 © 2009
Execution: 0.063. 11 queries. Compression Enabled.