Windows - Ajouter SNMP dans Panneau Config
Windows - Ajouter SNMP dans Panneau Config
Below is a VB script which copy's the SNMP files & INSTSRV.EXE from a share to systroot\system32\snmp on the local machine. It then uses instsrv.exe to install the "SNMP Service" and the "SNMP Trap Service" .... Then using WMI, it make's sure that both services are set to automatic and also starts the service. Finally it deletes instsrv.exe ... Walaa! SNMP is installed, started and can now be configured locally or via GPO! ENJOY!
I pulled these files out of %systemroot%\ServicePackFiles\i386 .. easiest way to find them is to search on the folder for snmp*.*
snmp.chm
snmp.exe
snmpapi.dll
snmpmib.dll
snmpsnap.dll
snmpsnap.hlp
snmptrap.exe
INSTSRV.EXE is part of the Windows Resource Kit.
Set Shell = Wscript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
'This little script will install the snmp services SNMP Service and SNMP Trap Service.
'Function SNMP --- copy's files from your share (you must edit that line) to the local PC under the sysroot\system32\snmp folder.
'It then run's instsrv.exe from this location and installs the two services, then deletes the file instsrv.exe ..
'Function root --- returns the system root using WMI..
'Function srvstart --- starts whatever service you plug into it..ie srvstart CHR(34) & "SNMP Service" & CHR(34)
'CHR(34) = double quotes..
snmp
wscript.sleep 3000
srvstart chr(34) & "SNMP Service" & CHR(34)
srvstart chr(34) & "SNMP Trap Service" & CHR(34)
wscript.quit
'---
Function snmp
root sysroot
FSO.copyFolder "\\server\share with snmp files & instsrv.exe",sysroot & "\system32\snmp",TRUE
shell.run sysroot & "\system32\snmp\instsrv.exe " & CHR(34) & "SNMP Service" & CHR(34) & " " & sysroot & "\system32\snmp\snmp.exe"
wscript.sleep 2000
shell.run sysroot & "\system32\snmp\instsrv.exe " & CHR(34) & "SNMP Trap Service" & CHR(34) & " " & sysroot & "\system32\snmp\snmptrap.exe"
wscript.sleep 5000
FSO.deleteFile sysroot & "\system32\snmp\instsrv.exe"
End Function
'---
Function root(sysroot)
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cim v2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
sysroot = objOperatingSystem.WindowsDirectory
Next
End Function
'---
'Start a service
Function srvstart (Service)
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cim v2")
Set colServices = objWMIService.ExecQuery("Select * from Win32_Service where Name=" & Service)
For Each objService in colServices
If objService.Started Then
'shell.popup "SERVICE IS ALREADY RUNNING!",3
'wscript.quit
End If
If UCASE(objService.StartMode) = "DISABLED" or UCASE(objService.StartMode) = "MANUAL" Then
errReturnCode = objService.ChangeStartMode("Automatic")
If errReturnCode <> 0 Then
errorlog errReturnCode
End If
WScript.Sleep 2000
End If
If Not objService.Started Then
errReturnCode = objService.StartService()
If errReturnCode <> 0 Then
errorlog errReturnCode
End If
WScript.Sleep 2000
End If
Next
Set colServices = Nothing
Set objWMIService = Nothing
End Function
Below is a VB script which copy's the SNMP files & INSTSRV.EXE from a share to systroot\system32\snmp on the local machine. It then uses instsrv.exe to install the "SNMP Service" and the "SNMP Trap Service" .... Then using WMI, it make's sure that both services are set to automatic and also starts the service. Finally it deletes instsrv.exe ... Walaa! SNMP is installed, started and can now be configured locally or via GPO! ENJOY!
I pulled these files out of %systemroot%\ServicePackFiles\i386 .. easiest way to find them is to search on the folder for snmp*.*
snmp.chm
snmp.exe
snmpapi.dll
snmpmib.dll
snmpsnap.dll
snmpsnap.hlp
snmptrap.exe
INSTSRV.EXE is part of the Windows Resource Kit.
Set Shell = Wscript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
'This little script will install the snmp services SNMP Service and SNMP Trap Service.
'Function SNMP --- copy's files from your share (you must edit that line) to the local PC under the sysroot\system32\snmp folder.
'It then run's instsrv.exe from this location and installs the two services, then deletes the file instsrv.exe ..
'Function root --- returns the system root using WMI..
'Function srvstart --- starts whatever service you plug into it..ie srvstart CHR(34) & "SNMP Service" & CHR(34)
'CHR(34) = double quotes..
snmp
wscript.sleep 3000
srvstart chr(34) & "SNMP Service" & CHR(34)
srvstart chr(34) & "SNMP Trap Service" & CHR(34)
wscript.quit
'---
Function snmp
root sysroot
FSO.copyFolder "\\server\share with snmp files & instsrv.exe",sysroot & "\system32\snmp",TRUE
shell.run sysroot & "\system32\snmp\instsrv.exe " & CHR(34) & "SNMP Service" & CHR(34) & " " & sysroot & "\system32\snmp\snmp.exe"
wscript.sleep 2000
shell.run sysroot & "\system32\snmp\instsrv.exe " & CHR(34) & "SNMP Trap Service" & CHR(34) & " " & sysroot & "\system32\snmp\snmptrap.exe"
wscript.sleep 5000
FSO.deleteFile sysroot & "\system32\snmp\instsrv.exe"
End Function
'---
Function root(sysroot)
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cim v2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
sysroot = objOperatingSystem.WindowsDirectory
Next
End Function
'---
'Start a service
Function srvstart (Service)
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cim v2")
Set colServices = objWMIService.ExecQuery("Select * from Win32_Service where Name=" & Service)
For Each objService in colServices
If objService.Started Then
'shell.popup "SERVICE IS ALREADY RUNNING!",3
'wscript.quit
End If
If UCASE(objService.StartMode) = "DISABLED" or UCASE(objService.StartMode) = "MANUAL" Then
errReturnCode = objService.ChangeStartMode("Automatic")
If errReturnCode <> 0 Then
errorlog errReturnCode
End If
WScript.Sleep 2000
End If
If Not objService.Started Then
errReturnCode = objService.StartService()
If errReturnCode <> 0 Then
errorlog errReturnCode
End If
WScript.Sleep 2000
End If
Next
Set colServices = Nothing
Set objWMIService = Nothing
End Function
Retour aux articles de la catégorie Informatique -
⨯
Inscrivez-vous au blog
Soyez prévenu par email des prochaines mises à jour
Rejoignez les 4 autres membres