Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to change Reg Key 2

Status
Not open for further replies.

MattWray

Technical User
Nov 2, 2001
2,332
0
0
US
Hello,

We made a mistake redirecting a folder to the server when it shouldn't have been. When I disable the policy, the key in the registry stays the same, so the problem does not go away. I need a script to change the registry key back to what it should be.
Can anyone help?

Thanks,

Matt Wray
MCSE, MCSA, MCP, CCNA

 
Opps, found mistake in the following:


REM Cleaning up files copied, and services created
del \\%1\SOME_SHARE_TO_SYSTEM_PARTITION\TEMP\reg.exe /Q
sc \\%1 delete "remote command"
del \\%1\SOME_SHARE_TO_SYSTEM_PARTITION\winnt\rcmdsvc.exe /Q


REPLACE with this
REM Cleaning up files copied, and services created
del \\%1\SOME_SHARE_TO_SYSTEM_PARTITION\TEMP\reg.exe /Q
sc \\%1 stop "remote command"
sc \\%1 delete "remote command"
del \\%1\SOME_SHARE_TO_SYSTEM_PARTITION\winnt\rcmdsvc.exe /Q
 
Sorry about not getting back. I was swamped today.
I do have the Reskit, I can run it from either a PC or a server, the reskit is on a server, I can use the default c$ share.

I will give those changes a try and let you know.

Thanks again!

Thanks,

Matt Wray
MCSE, MCSA, MCP, CCNA

 
Stiddy:
That's some great stuff you posted. I gave you a star, even though I tried your script and it didn't quite work out perfectly. My organization running WindowsXP Pro, and we've deployed 80 machines already. We have a need to put a login security notice, located in
HKLM\Software\Microsoft\Windows NT\CurrentVersion\WinLogon

under two keys:
LegalNoticeCaption
LegalNoticeText

I've got two batch files, readlist.bat and regupd.bat .
==========================================================
readlist.bat:
for /f "tokens=1-2" %%a in (c:\test\workstat.txt) do call c:\test\regupd.bat %%a

regupd.bat:
REM This batch file will loop until the complete computer list
REM is read. Each computer name from workstat.txt will be read
REM into this batch program as a variable %1 .

REM This part will copy the executable service program to the remote
REM computer, to whatever path specified below
xcopy rcmdsvc.exe \\%1\c$ /y

REM This part will create the rcmdsvc.exe (Remote Command Service)
REM service on the remote computer.
sc \\%1 create "remote command" binpath= c:\rcmdsvc.exe

REM This part will start the service that we just created on the
REM remote computer.
sc \\%1 start "remote command"

REM Now we can execute any command we want on the remote computer.
REM Keep in mind, that you will need to specify the full path
REM of the command. If the path or filename is longer than
REM 8 characters, you will need to enclose the path with
REM double-quotation marks, "" . Also, you cannot import a registry
REM entry into \\HKEY_CURRENT_USER, as that key is on a per-user
REM basis, and must be imported locally on the workstation under
REM the user's credentials.
rcmd \\%1 c:\windows\regedit.exe /s /i \\<server name>\netlogon\disclaimer.reg

REM The remote command is now finished. Now we will stop and
REM then delete the remote service we just created.
sc \\%1 stop &quot;remote command&quot;
sc \\%1 delete &quot;remote command&quot;

REM Now finally we will remote the remote command service executable
REM file from the remote machine
del \\%1\c$\rcmdsvc.exe /q

REM This last entry will keep track of which registry changes
REM were successful. If the computer name is not in the log
REM file, then the reg change was not successful.
Echo >> C:\test\complete.log %1 Registry change complete

REM All done!
==========================================================

Now the problem is that the batch file executes correctly on the client side, but on the remote side, the registry does not import properly. I can walk over to the remote computer, log in with administrator rights, and run the exact same commmand, and it works fine. Is there some quirk that I'm not aware of, by using the rcmd command with regedit? I realize this is a stale post, but it hits the nail on the head for what my organization is trying to do, AND the batch file provides a great amount of flexibility for what we can also do down the road. Thanks!
 
xyrx,

Great job commenting your batch program. You can never make to much effort to inform other users of what the program is doing. Lets face it, if they cant read it and understand exactly what it is doing, they shouldn't be using it.

So from my experience, briefly looking at the registry keys you are trying to use, it appears you are trying to display a legal notice to all of your end-users. Great. I think it is failing remotely because you are using the wrong executable to do the job. I know you are thinking, &quot;Stiddy said that using the remote command utilty will execute files on the remote machine&quot;, which it does, but I don't think that 'regedit.exe' is what you need. I believe that you need to use the 'reg.exe' executable from the NT Resource kit. This is what you need to do.

Change your batch file to something like this. Oh, by the way, nothing is hurt by leaving the &quot;Remote Command&quot; server running on your client machines. It will prevent you from having to code it into every other script your ever right. You can configure the service to start automatically so in the future you dont have to worry about it like such:
sc \\%1 config &quot;remote command&quot; start= Auto

In the batch file I am suggesting, notice that we are not using remote command, but you can copy it out if you want:

REM #### Your modified regupd.bat ####
REM This batch file will loop until the complete computer list
REM is read. Each computer name from workstat.txt will be read
REM into this batch program as a variable %1 .

REM This will modify the registry keys on each computer from the workstat.txt file.
REM We are using the NT RESOURCE KIT Utilty 'reg.exe'
REM Modifying the LegalNoticeCaption which is the title of the dialog box presented to each user.
REM xyrx, it is critical that no spaces are present between the = sign and your text
reg update &quot;HKLM\Software\Microsoft\Windows NT\CurrentVersion\WinLogon\LegalNoticeCaption=[WARNING!] THIS IS A DOD COMPUTER SYSTEM!!&quot; \\%1

REM Modifying the LegalNoticeText which is the text portion of the dialog box presented to each user.
REM xyrx, it is critical that no spaces are present between the = sign and your text
reg update &quot;HKLM\Software\Microsoft\Windows NT\CurrentVersion\WinLogon\LegalNoticeText=&quot;By accessing and using this system you are consenting to system monitoring for law enforcement and other purposes. Unauthorized use of this computer system may subject you to criminal prosecution and penalties.&quot; \\%1

REM This last entry will keep track of which registry changes
REM were successful. If the computer name is not in the log
REM file, then the reg change was not successful.
Echo >> C:\test\complete.log %1 Registry change complete
REM #### End of batch file ####

Hope this helps you. You could also consider using 'reg.exe import' from the Windows 2000 resource kit to remotely import a .reg file on each remote machine like you were trying to do with 'regedit.exe'. I have never gotten the NT resource kit 'reg.exe' to import .reg files like I wanted. So as the alter I would dircetly modify the registry like I shoulded you above.

 
Thanks so much Stiddy, this did the trick. I was using the reg.exe from the Win2k reskit, and had to play with that for 45 minutes to get it to import (the syntax was different) . You were right, in that it wasn't cooperating when trying to import a reg file, but would work by specifying the precise key to add. I had mis-typed the commandline options for one of the reg commands, and accidentally hosed one of our IT user's computers. However I would have recommended he format it anyway, as I found gator and some other spyware junk on there.

We now have a working script to change reg keys over the network. Thanks again!
 
Glad I could help. Just ask if you need any more assistance for I read post daily, and recommend this site to everyone whom I think can benefit its purpose.


Stiddy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top