Need a batch/vbs script that will modify a registry value.

mystikal1000
mystikal1000 used Ask the Experts™
on
I need a script that will modify a registry value on over 100+ servers.  The best way is for the script to read the servers.txt file and update all of the server in the txt. file.  I need this asap.  I appreciate it.

String Registry value
Location:
HKEY_LOCAL_MACHINE\SOFTWARE\AppSense Technologies\Communications Agent

Value:
WebSite
event url
deployment url

Data:
server1
server2
server3
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
What OS are the servers?

Author

Commented:
Windows 2003.

Commented:
Oh and what types of registry values are they?  REG_SZ, DWORD, etc.

Author

Commented:
REG_SZ
rejoinderManager, IT
Top Expert 2008

Commented:
If this is a repeatable registry change and one that might be done as machines are added to your domain... why not use your Group Policy Management Editor?
Create a new policy, go to Computer Configuration, Preferences, Windows Settings, Registry.  From there you can create new policies to add/update registry keys and values.  Apply the policy to the proper OU or if there are machines you want specifically you can remove the Authenticated Users from the scope tab in the policy editor and enter in the 100 machine names yourself.

This is just a suggestion, a script will work like a charm too.

Author

Commented:
I am familiar with GPO's, but no this is more of a one off.

Commented:
Test this out:

Set oShell = CreateObject("WScript.Shell")
RegKey = "HKLM\SOFTWARE\AppSense Technologies\Communications Agent\"
oShell.RegWrite RegKey & "WebSite", "server1"
oShell.RegWrite RegKey & "event url", "server2"
oShell.RegWrite RegKey & "deployment url", "server3"

Open in new window

Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Try this batch script (after making the necessary adjustments). The script will create a log file with the results, just in case a server won't cooperate.
@echo off
setlocal
set ServerFile=servers.txt
set RegKey=HKEY_LOCAL_MACHINE\SOFTWARE\AppSense Technologies\Communications Agent
set LogFile=%~dpn0.log
>"%LogFile%" echo Server;Result;Errorlevel
for /f %%a in ('type "%ServerFile%"') do call :Process %%a
echo Done.
goto :eof
:Process
set Server=%~1
echo Processing %Server% ...
reg.exe add "\\%Server%\%RegKey%" /v "Website" /t REG_SZ /d "Server1" /f
if errorlevel 1 (
  >>"%LogFile%" echo %Server%;Error;%Errorlevel%
  goto :eof
)
REM The first entry was successful, assuming the rest will now work, too:
reg.exe add "\\%Server%\%RegKey%" /v "Event URL" /t REG_SZ /d "Server2" /f
reg.exe add "\\%Server%\%RegKey%" /v "Deployment URL" /t REG_SZ /d "Server3" /f
>>"%LogFile%" echo %Server%;OK;0
goto :eof

Open in new window

Author

Commented:
Great job

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial