Batch script to configure SNMP services

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here a way to install and configure remotely from Microsoft.
There is some script code with examples.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

ReyesrjAuthor Commented:
Thanks Guys!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.