Page 1 of 1 1
Topic Options
#148044 - 2005-09-19 03:17 PM Automated install of SNMP
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
We use the script below to install SNMP on all our workstations.
The original idea came from How to deploy SNMP silently in kix ?.
I altered it a bit, added the OS selection section cause we Use Win2k and WinXP also removed the part that deals with a whole bunch of HP/Compaq services. We use Dell and therefore don’t need the HP/Compaq stuff.
By altering it it became just a basic SNMP install script. Off course it should be modified to you’re specific situation and it can be used to (un)install other OS components also (see the MS link).

Sysinternals - PSEXEC.EXE
Microsoft - SYSOC.EXE/INF stuff


Code:

;Installs and configures SNMP.
;
;Tested on: Windows 2000 SP4 and Windows XP SP2 using KixTart 4.50Beta1
;
;Requires: PSEXE.EXE - Freeware from sysinternals.
; http://www.sysinternals.com/utilities/psexec.html
; SYSOCMGR.EXE - Located and should stay in %windir%\system32.
; SYSOC.INF - Located and should stay in %windir%\inf.
; ??.TXT - Components to (un)install.
; http://support.microsoft.com/default.aspx?scid=kb;en-us;222444
; I386 folder - Just copy it from OS/SP CD.
; XNET.EXE - Available in older KixTart releases (4.23 and older).
; http://www.kixtart.org
;
;Based on: http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=131498&an=&page=0&vc=1
;
;Example: kix32.exe snmp.kix $remotepc=pc1
;
;
;Check if pc to execute on is set at command line.
If $remotepc = ""
$remotepc = @WKSTA
EndIf
;
;Set variables.
$key1 = "HKLM\software\Microsoft\Windows NT\CurrentVersion"
$key2 = "HKLM\SYSTEM\ControlSet001\Services"
$key3 = "HKLM\SYSTEM\CurrentControlSet\Services"
$key4 = "HKLM\software\Microsoft\Windows\CurrentVersion"
$key5 = "HKLM\SYSTEM\CurrentControlSet\Control\ServiceCurrent"
$key6 = "HKLM\SYSTEM\ControlSet001\Control\ServiceCurrent"
$sourcepath = ReadValue("\\" + $remotepc + "\" + $key1,"SourcePath")
$sourcepath2 = ReadValue("\\" + $remotepc + "\" + $key4 + "\Setup","SourcePath")
$sourcepath3 = ReadValue("\\" + $remotepc + "\" + $key4 + "\Setup","ServicePackSourcePath")
$winver = ReadValue ("\\" + $remotepc + "\" + $key1,"Productname")
;
;Select OS.
Select
Case InStr ($winver, "XP")
;write temp source path.
$rc = WriteValue("\\" + $remotepc +
"\" + $key1,"SourcePath","\\server\share\winxp\I386","Reg_SZ")
$rc = WriteValue("\\" + $remotepc +
"\" + $key4 + "\Setup","SourcePath","\\server\share\winxp\","Reg_SZ")
$rc = WriteValue("\\" + $remotepc + "\" + $key4 +
"\Setup","ServicePackSourcePath","\\server\share\winxp\SP2\","Reg_SZ")
;install snmp
Shell "\\server\share\PSEXEC.EXE \\" + $remotepc +
" -s -i sysocmgr.exe /i:%windir%\inf\sysoc.inf /u:\\server\share\snmp.txt /q"
ConfigSNMP()
Case InStr ($winver, "2000")
;write temp source path.
$rc = WriteValue("\\" + $remotepc +
"\" + $key1,"SourcePath","\\server\share\win2k\I386","Reg_SZ")
$rc = WriteValue("\\" + $remotepc +
"\" + $key4 + "\Setup","SourcePath","\\server\share\win2k\","Reg_SZ")
$rc = WriteValue("\\" + $remotepc + "\" + $key4 +
"\Setup","ServicePackSourcePath","\\server\share\win2k\SP4\","Reg_SZ")
;install snmp.
Shell "\\server\share\PSEXEC.EXE \\" + $remotepc +
" -s -i sysocmgr.exe /i:%windir%\inf\sysoc.inf /u:\\server\share\snmp.txt /q"
ConfigSNMP()
EndSelect
;
Function ConfigSNMP()
;write snmp settings to registry.
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\kmixer\Enum", "0", "SW\{b7eafdc0-a680-11d0-96d8-00aa0051e51d}\{9B365890-165F-11D0-A195-0020AFD156E4}", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\SNMP\Parameters\TrapConfiguration\public", "1", "192.168.1.16", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\kmixer\Enum", "Count", "1", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\kmixer\Enum", "NextInstance", "1", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\SNMP\Parameters\RFC1156Agent", "sysContact", "SNMP Contact", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\SNMP\Parameters\RFC1156Agent", "sysLocation", "Ssytem location", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\SNMP\Parameters\ValidCommunities", "public", "8", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\kmixer\Enum", "0", "SW\{b7eafdc0-a680-11d0-96d8-00aa0051e51d}\{9B365890-165F-11D0-A195-0020AFD156E4}", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\SNMP\Parameters\TrapConfiguration\public", "1", "192.168.1.16", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\kmixer\Enum", "Count", "1", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 + "\kmixer\Enum", "NextInstance", "1", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\SNMP\Parameters\RFC1156Agent", "sysContact", "SNMP contact", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\SNMP\Parameters\RFC1156Agent", "sysLocation", "System location", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\SNMP\Parameters\ValidCommunities", "public", "8", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" +
$key6, "", "76", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\SNMPTrap", "ObjectName", "LocalSystem", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" +
$key5, "", "76", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\SNMPTrap", "ObjectName", "LocalSystem", "REG_SZ")
;set install path to original settings.
$rc = WriteValue("\\" + $remotepc +
"\" + $key1,"SourcePath",$SourcePath,"Reg_SZ")
$rc = WriteValue("\\" + $remotepc +
"\" + $key4 + "\Setup","SourcePath",$SourcePath2,"Reg_SZ")
$rc = WriteValue("\\" + $remotepc + "\" + $key4 +
"\Setup","ServicePackSourcePath",$SourcePath3,"Reg_SZ")
;stop and start snmp to be sure new settings are used.
Shell "\\server\share\Xnet.exe stop \\" + $remotepc + "\SNMP"
Sleep 10
Shell "\\server\share\Xnet.exe start \\" + $remotepc + "\SNMP"
Sleep 10
EndFunction



[edit 21-sept-2005]
Code update.
Added servicepack sourcepath.
Resolved always use xp install even on win2k.
[/edit]


Edited by Mart (2005-09-21 12:33 PM)

Top
#148045 - 2005-09-19 03:49 PM Re: Automated install of SNMP
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Small change:

The SNMP Trap service now starts using the localsystem account.
Code above updated.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#148046 - 2005-09-19 04:47 PM Re: Automated install of SNMP
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Be advised that PSEXEC can be a security risk.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#148047 - 2005-09-19 05:21 PM Re: Automated install of SNMP
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yep, I know. We are planning to do it on sneaker net in the near future cause we need to attend all machines unfortunately so we will not need PSEXEC.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#148048 - 2005-09-21 12:35 PM Re: Automated install of SNMP
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Unable to edit the post above so here's a code update.

Code:

;Installs and configures SNMP.
;
;Tested on: Windows 2000 SP4 and Windows XP SP2 using KixTart 4.50Beta1
;
;Requires: PSEXE.EXE - Freeware from sysinternals.
; http://www.sysinternals.com/utilities/psexec.html
; SYSOCMGR.EXE - Located and should stay in %windir%\system32.
; SYSOC.INF - Located and should stay in %windir%\inf.
; ??.TXT - Components to (un)install.
; http://support.microsoft.com/default.aspx?scid=kb;en-us;222444
; I386 folder - Just copy it from OS/SP CD.
; XNET.EXE - Available in older KixTart releases (4.23 and older).
; http://www.kixtart.org
;
;Based on: http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=131498&an=&page=0&vc=1
;
;Example: kix32.exe snmp.kix $remotepc=pc1
;
;
;Check if pc to execute on is set at command line.
If $remotepc = ""
$remotepc = @WKSTA
EndIf
;
;Set variables.
$key1 = "HKLM\software\Microsoft\Windows NT\CurrentVersion"
$key2 = "HKLM\SYSTEM\ControlSet001\Services"
$key3 = "HKLM\SYSTEM\CurrentControlSet\Services"
$key4 = "HKLM\software\Microsoft\Windows\CurrentVersion"
$key5 = "HKLM\SYSTEM\CurrentControlSet\Control\ServiceCurrent"
$key6 = "HKLM\SYSTEM\ControlSet001\Control\ServiceCurrent"
$sourcepath = ReadValue("\\" + $remotepc + "\" + $key1,"SourcePath")
$sourcepath2 = ReadValue("\\" + $remotepc + "\" + $key4 + "\Setup","SourcePath")
$sourcepath3 = ReadValue("\\" + $remotepc + "\" + $key4 + "\Setup","ServicePackSourcePath")
$winver = ReadValue ("\\" + $remotepc + "\" + $key1,"Productname")
;
;Select OS.
Select
Case InStr ($winver, "XP")
;write temp source path.
$rc = WriteValue("\\" + $remotepc +
"\" + $key1,"SourcePath","\\server\share\winxp\I386","Reg_SZ")
$rc = WriteValue("\\" + $remotepc +
"\" + $key4 + "\Setup","SourcePath","\\server\share\winxp\","Reg_SZ")
$rc = WriteValue("\\" + $remotepc + "\" + $key4 +
"\Setup","ServicePackSourcePath","\\server\share\winxp\SP2\","Reg_SZ")
;install snmp
Shell "\\server\share\PSEXEC.EXE \\" + $remotepc +
" -s -i sysocmgr.exe /i:%windir%\inf\sysoc.inf /u:\\server\share\snmp.txt /q"
ConfigSNMP()
Case InStr ($winver, "2000")
;write temp source path.
$rc = WriteValue("\\" + $remotepc +
"\" + $key1,"SourcePath","\\server\share\win2k\I386","Reg_SZ")
$rc = WriteValue("\\" + $remotepc +
"\" + $key4 + "\Setup","SourcePath","\\server\share\win2k\","Reg_SZ")
$rc = WriteValue("\\" + $remotepc + "\" + $key4 +
"\Setup","ServicePackSourcePath","\\server\share\win2k\SP4\","Reg_SZ")
;install snmp.
Shell "\\server\share\PSEXEC.EXE \\" + $remotepc +
" -s -i sysocmgr.exe /i:%windir%\inf\sysoc.inf /u:\\server\share\snmp.txt /q"
ConfigSNMP()
EndSelect
;
Function ConfigSNMP()
;write snmp settings to registry.
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\kmixer\Enum", "0", "SW\{b7eafdc0-a680-11d0-96d8-00aa0051e51d}\{9B365890-165F-11D0-A195-0020AFD156E4}", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\SNMP\Parameters\TrapConfiguration\public", "1", "192.168.1.16", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\kmixer\Enum", "Count", "1", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\kmixer\Enum", "NextInstance", "1", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\SNMP\Parameters\RFC1156Agent", "sysContact", "SNMP Contact", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\SNMP\Parameters\RFC1156Agent", "sysLocation", "Ssytem location", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\SNMP\Parameters\ValidCommunities", "public", "8", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\kmixer\Enum", "0", "SW\{b7eafdc0-a680-11d0-96d8-00aa0051e51d}\{9B365890-165F-11D0-A195-0020AFD156E4}", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\SNMP\Parameters\TrapConfiguration\public", "1", "192.168.1.16", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\kmixer\Enum", "Count", "1", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 + "\kmixer\Enum", "NextInstance", "1", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\SNMP\Parameters\RFC1156Agent", "sysContact", "SNMP contact", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\SNMP\Parameters\RFC1156Agent", "sysLocation", "System location", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\SNMP\Parameters\ValidCommunities", "public", "8", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" +
$key6, "", "76", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key2 +
"\SNMPTrap", "ObjectName", "LocalSystem", "REG_SZ")
$rc = WriteValue ("\\" + $remotepc + "\" +
$key5, "", "76", "REG_DWORD")
$rc = WriteValue ("\\" + $remotepc + "\" + $key3 +
"\SNMPTrap", "ObjectName", "LocalSystem", "REG_SZ")
;set install path to original settings.
$rc = WriteValue("\\" + $remotepc +
"\" + $key1,"SourcePath",$SourcePath,"Reg_SZ")
$rc = WriteValue("\\" + $remotepc +
"\" + $key4 + "\Setup","SourcePath",$SourcePath2,"Reg_SZ")
$rc = WriteValue("\\" + $remotepc + "\" + $key4 +
"\Setup","ServicePackSourcePath",$SourcePath3,"Reg_SZ")
;stop and start snmp to be sure new settings are used.
Shell "\\server\share\Xnet.exe stop \\" + $remotepc + "\SNMP"
Sleep 10
Shell "\\server\share\Xnet.exe start \\" + $remotepc + "\SNMP"
Sleep 10
EndFunction

_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

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 1527 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.057 seconds in which 0.028 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