Batch script to configure SNMP services

Posted on 2014-08-18
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

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

    LVL 82

    Assisted Solution

    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

    Thanks Guys!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    I recently purchased an HP EliteBook 2540p notebook/laptop. It has two video ports on it – VGA and DisplayPort. HP offers an optional docking station for the 2540p that also has both a VGA port and a DisplayPort. There are numerous online reports do…
    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
    This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now