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

 
You can use vbscripting to do this. whats the name of the key?

You can use something like this

set objShell=Wscript.CreateObject("wscript.Shell")
objShell.RegWrite "HKLM\software\mircosoft\windows nt\", {value}, "{name of data type i.e. REG_DWORD}"


so the syntax is "the reg key", data, "data type"


thats it.
 
The key is HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\AppData
It was accidentally changed to a UNC path to one of the servers. It needs to be the default, %USERPROFILE%\Application Data.
I have not used vbscripting before, so all details would be appreciated.
Thanks!

Thanks,

Matt Wray
MCSE, MCSA, MCP, CCNA

 
Does this look right?
set objShell=Wscript.CreateObject("wscript.Shell")
objShell.RegWrite "HKEY_CURRENT_USER\software\mircosoft\windows\CurrentVersion\Explorer\User Shell Folders\AppData", %USERPROFILE%\Application Data, "REG_EXPAND_SZ"



Thanks,

Matt Wray
MCSE, MCSA, MCP, CCNA

 
Matt,

I would write two batch files like such:

Rem Batch to read in all workstations to modify
for /f "tokens=1-2" %%a in (c:\bats\auto\my_workstations.txt) do call d:\bats\auto\fix_registry_muckup.bat %%a
Rem End batch auto_read_in_workstations.bat



Rem Batch to actually modify the registry settings on all the machines in question
reg update "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\AppData=%USERPROFILE%\Application Data" \\%1
Echo Comleted workstation %1
Rem End of fix_registry_muckup.bat



HTH - MIKE
 
Is the first simply to verify that the bad line is there? Can they both be included in one?

Thanks,

Matt Wray
MCSE, MCSA, MCP, CCNA

 
The first batch is simply to read in a text file full of hostnames and then pass them off to the other bacth to perform the actions you want. Like for example, make the first batch file out of this one liner:

for /f "tokens=1-2" %%a in (c:\bats\auto\my_workstations.txt) do call d:\bats\auto\lets_ping.bat %%a



Then make a text file full of hostnames name 'my_workstations.txt like such:

ComputerA
ComputerB
ComputerC
ComputerD


Thirdly, make another bacyh file called 'lets_ping.bat' with the contents:

ping %1






You will see that the first batch grabs the each hostname line by line and passes it to the lets_ping.bat and pings each workstation in 'my_workstations.txt'


HTH - MIKE

 
Just to clarify, I need to make a text file called my_workstations.txt, for your above example, and add the hostnames of the machines I want to check. I need to include the directory it is saved in, c:\bats\auto\ in your example. Then run the first .BAT followed by the second? Should I actually include that first line, or is that just an explanation? "Rem Batch to read in all workstations to modify"
Would this matter where it is run from? Can I run it from a single machine, or put it in a login script?
Sorry for the basic questions, I am not too experienced with scripts!


Thanks,

Matt Wray
MCSE, MCSA, MCP, CCNA

 
Matt,

You can put the files anywhere you want. But, just for the example to be simple, put them all on the root of your c drive. You only need run one batch file by double clicking it. So take this one liner and paste it into notepad and save it as c:\auto_read_in_workstations.bat
for /f "tokens=1-2" %%a in (c:\my_workstations.txt) do call c:\lets_ping.bat %%a


Now, create the my_workstations.txt with about 10 or so hostnames of workstations in your network, and also save it in the root of your c drive.



Last, open notepad one more time and add the command:
ping %1
then save it as c:\lets_ping.bat



Double click auto_read_in_workstations.bat and watch how every one of your workstations in the my_workstation.txt file are pinged via the lets_ping.bat file.
 
Matt, sorry for I did not answer all of your questions.

"Can I run it from a single machine, or put it in a login script?"

The hole idea I am trying to sell you is, once you have got these three files created. We could then modify only one of them to accomplish the registry change you need to make. Doesn't matter if you have to change 10 machines or 10000, you will run the main bacth file from say, your personal machine and under your profile which is probably an domain admin or enterprise admin whom has rights to modify the regisry on all the workstations, then go get some coffee or have a cig. It will do all the work for you. HTH
 
If he wants to automate this process it would be best to place it in a logon script and just and lines to check for the bad key, if exist then goto batch, if not then end.
 
It did not work. It seems it wants to put in my AppData info. I also tried adding it as a logon script, but still no go. Here is what happened, any ideas?

C:\Bats\Auto>dir
Volume in drive C has no label.
Volume Serial Number is 40EB-1E00

Directory of C:\Bats\Auto

08/11/2003 07:10 AM <DIR> .
08/11/2003 07:10 AM <DIR> ..
08/11/2003 07:06 AM 157 auto_read_in_workstations.bat
08/11/2003 07:22 AM 212 fix_registry_muckup.bat
08/11/2003 07:20 AM 42 my_workstations.txt
3 File(s) 411 bytes
2 Dir(s) 11,914,530,816 bytes free

C:\Bats\Auto>auto_read_in_workstations.bat

C:\Bats\Auto>for /F &quot;tokens=1-2&quot; %a in (c:\bats\auto\my_workstations.txt) do cal
l c:\bats\auto\fix_registry_muckup.bat %a

C:\Bats\Auto>call c:\bats\auto\fix_registry_muckup.bat testmachine1.sss-steel.co
m

C:\Bats\Auto>reg update &quot;HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVer
sion\Explorer\User Shell Folders\AppData=C:\Documents and Settings\Matt Wray.MAT
TLAPTOP\Application Data&quot;
\\testmachine1.sss-steel.com

Error: Bad operation. Use /? for help

C:\Bats\Auto>Echo Comleted workstation testmachine1.sss-steel.com
Comleted workstation testmachine1.sss-steel.com

C:\Bats\Auto>Rem End of fix_registry_muckup.bat

C:\Bats\Auto>call c:\bats\auto\fix_registry_muckup.bat 192.168.77.106

C:\Bats\Auto>reg update &quot;HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVer
sion\Explorer\User Shell Folders\AppData=C:\Documents and Settings\Matt Wray.MAT
TLAPTOP\Application Data&quot;
\\192.168.77.106

Error: Bad operation. Use /? for help

C:\Bats\Auto>Echo Comleted workstation 192.168.77.106
Comleted workstation 192.168.77.106

C:\Bats\Auto>Rem End of fix_registry_muckup.bat

C:\Bats\Auto>Rem End batch auto_read_in_workstations.bat

C:\Bats\Auto>

Thanks,

Matt Wray
MCSE, MCSA, MCP, CCNA

 
Matt,

Try changing HKEY_CURRENT_USER to HKCU\blahblah
 
Matt,

Also, this line in the first batch should contain %%a like such:

for /F &quot;tokens=1-2&quot; %%a in (c:\bats\auto\my_workstations.txt) do cal
l c:\bats\auto\fix_registry_muckup.bat %%a
 
Matt,

the syntax of the reg update part of your batch file also depends on the version of reg.exe that you are using. I use reg.exe from the NT resource kit, but if you are using the one from the W2K resource pro kit, then I think you can not update a registry key. You have to selete the key and then recreate it....
 
Matt, I have been hacking at this for a few minutes and found out how to help you. So, yes you can run from a script, but unfortunetly you can not update HKEY_CURRENT_USER remotely. You have to do it from the local machine. But dont fret, if you say you have the W2k resource kit this can be accomplished easily still. If you would not mind, answer a few questions for me.

1 - Do you have the w2k resource kit?
2 - Are you gonna run this batch from your personal wks or a server somewhere?

3 - Where is the resource kit installed?
4 - What is the path where the resoucre kit is installed?
5 - What is the name of a share available on all your workstations where you have full access to the root of the system partition?

6 - If you dont feel like typing all this stuff then email me and I will respond with my number. It's no problem cause I am at work.

Mike
michael.stidham@us.ibm.com
 
Matt,

Put the contents below file into the fix_registry_muckup.bat file and add one test machine into the my_workstations.txt file. Run this and see if it works for you.



REM Changing directories where all files are located
c:
cd progra~1\resour~1\rcmd


REM Copies the executable needed for remote command line administration
REM Make sure to change the SOME_SHARE_TO_SYSTEM_PARTITION part
REM to a shared that is available on every workstations root
REM system partition
xcopy rcmdsvc.exe \\%1\SOME_SHARE_TO_SYSTEM_PARTITION\winnt /Y
cd..



REM Creates a service on remote machine for connecting vai command line
REM Make sure to change DRIVE_LETTER to the actual drive letter on each workstations
REM system partition, usually c.
REM Also, notice the space in front of DRIVE_LETTER, it is immportant the remain there
sc \\%1 create &quot;remote command&quot; binpath= DRIVE_LETTER:\winnt\rcmdsvc.exe



REM Starts the Remote Commmand service on remote machine
sc \\%1 start &quot;remote command&quot;



REM Copies executable to remote machine to perform regisrty change
xcopy reg.exe \\%1\SOME_SHARE_TO_SYSTEM_PARTITION\TEMP /Y



REM Performing registry change on remote machine
rcmd \\%1 c:\temp\reg ADD &quot;HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders&quot; /v AppData /t REG_EXPAND_SZ /d &quot;%&quot;USERPROFILE&quot;%\Application Data&quot; /f



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



REM Writing to a log file so we know the registry change was
REM completed on each machine for future reference
Echo >> C:\Bats\Auto\Completed_workstations.log %1 Registry change complete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top