[Webinar] Learn how to a build a cloud-first strategyRegister Now


Batch script to configure SNMP services

Posted on 2014-08-18
Medium Priority
Last Modified: 2014-08-21
Hi All,

Please show me how to create a batch script for SNMP Service in a windows 7 Services (Local).

-      Under the Agent tab: I would like all the boxes checked.
-      Under the Security tab:
o      Add a community Name
o      Accept SNMP packets from these hosts marked (and add two ips)

Thank you in advance
Question by:Reyesrj
LVL 23

Accepted Solution

ComputerTechie earned 1000 total points
ID: 40270171
Here a way to install and configure remotely from Microsoft.

There is some script code with examples.

LVL 85

Assisted Solution

oBdA earned 1000 total points
ID: 40270955
Try the script below.
* Set as many Communities[] variables as you need and set them to the permissions you want (see the two examples with "foo" and "bar").
* AcceptedHosts is a simple space separated list of hosts to enter.
* For the Agent settings, set the Services variable with the "SERVICE_..." constants you need, separated by pipes.
* No entries will be deleted.
* There'll be a confirmation dialog before the script actually changes anything.
@echo off
setlocal enabledelayedexpansion
call :Init
set Communities[foo]=%ACCESS_READWRITE%
set Communities[bar]=%ACCESS_NOTIFY%
set AcceptedHosts=localhost
set /a Services = "SERVICE_Physical | SERVICE_DataLink_and_Subnet | SERVICE_Internet | SERVICE_End_to_end | SERVICE_Application"

echo Will configure the SNMP services as follows:
echo Services: %Services%
echo Communities:
for /f "tokens=2,3 delims=[]=" %%a in ('set Communities[') do echo 	- %%a: %%b
echo Accepted hosts:
for %%a in (%AcceptedHosts%) do echo 	- %%~a
set Confirm=n
set /p Confirm=Continue [y/N]? 
if /i not "%Confirm%"=="y" goto :eof
echo Configuring Services ...
reg.exe add "%SNMPKey%\RFC1156Agent" /v "sysServices" /t REG_DWORD /d %Services% /f 

echo Configuring Communities ...
for /f "tokens=2,3 delims=[]=" %%a in ('set Communities[') do (
	echo 	- %%a: %%b ...
	reg.exe add "%SNMPKey%\ValidCommunities" /v "%%a" /t REG_DWORD /d %%b /f

echo Configuring Accepted Hosts ...
for /f "tokens=2,3*" %%a in ('reg.exe query "%SNMPKey%\PermittedManagers" ^| find /i "REG_SZ"') do (
	set AcceptedHosts[%%b]=%%a
for %%a in (%AcceptedHosts%) do (
	echo 	- %%~a ...
	if defined AcceptedHosts[%%~a] (
		echo ... already present
	) else (
		call :GetFreeIndex
		reg.exe add "%SNMPKey%\PermittedManagers" /v "!Index!" /t REG_SZ /d "%%~a" /f
echo Restarting SNMP service ...
net stop SNMP
net start SNMP
echo Done.

goto :eof
set /a Index = 1
reg.exe query "%SNMPKey%\PermittedManagers" /v "%Index%" >NUL 2>&1
if errorlevel 1 goto :eof
set /a Index += 1
goto Loop

set SNMPKey=HKLM\SYSTEM\CurrentControlSet\Services\SNMP\Parameters

set /a SERVICE_Physical =				0x01
set /a SERVICE_DataLink_and_Subnet =	0x02
set /a SERVICE_Internet =				0x04
set /a SERVICE_End_to_end =				0x08
set /a SERVICE_Application =			0x40

set /a ACCESS_NONE =		0x0001 
set /a ACCESS_NOTIFY =		0x0002 
set /a ACCESS_READONLY =	0x0004 
set /a ACCESS_READWRITE =	0x0008 
set /a ACCESS_READCREATE = 	0x0010

goto :eof

Open in new window


Author Closing Comment

ID: 40275723
Thanks Guys!

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question