Link to home
Create AccountLog in
Avatar of stoneyrok
stoneyrok

asked on

import registry key remotely

Hi all,
I have a .reg key file that I need to import into workstations on our domains now and then. Luckily for me, the key is in the same location per machine, so that makes things a little easier. Bascially, a key gets changed when an event occurs, then the user will call the helpdesk. I'd like to have the helpdesk be able to double click an icon, be presented with a bix asking for the hostname of the PC, then they submit, and the key changes. A reboot is not immediately required, and I don't care if we have to use a copy command to get the .reg file to that PC, then a psexec command to execute it. All the helpdesk members have admin rights on all enterprise PC's, so permissions will not be ab issue either.
thanks so much. I am a very sloppy scripter, but might be able to figure it out with lots of research, trial, and error, where I am sure there are some killer scripters who know this stuff by heart! I hope, and thanks.
Avatar of oBdA
oBdA

For starters, a very basic batch script using psexec just to test whether it works for you:
@echo off
setlocal
set RegFile=\\SomeServer\SomeShare\test.reg
set RemoteFolder=C:\Windows\Temp
set /p RemoteComputer=Enter the computer name: 
if "%RemoteComputer%"=="" goto :eof
copy "%RegFile%" "\\%RemoteComputer%\%RemoteFolder::=$%"
psexec.exe \\%RemoteComputer% reg.exe import "%RemoteFolder%"

Open in new window

There might be better solutions, though; can you post the reg file (change any confidential information)?
Avatar of stoneyrok

ASKER

sure! and thanks. There is no confidential info in this particular reg file. It is a key that we need to set back after Windows Updates Run. Windows Updates changes the rightfax printer back to a windows printer, and this .reg will flip it back to "RFPrint" / well, there are three lines where I removed our domain name... each location starts with 940-stonew7.
thank you!  I am going to start messing with this today in a bit. It looks like I will need psexec on the remote PC. my concern now, is the first time that is run on a PC, we have to accept (click) their EULA.
FixRightFaxRegKey.reg
The logic of this looks beautiful!  It will copy the .reg file to the other PC which we indicate, and into the remote folder defined. BUT the key does not show in the registry. Here is what happens. On the Master PC, I get a message stating "Starting PsExec service on "SomePC" , and after about 10 seconds it goes away. On the target PC, I see the .reg file where it is supposed to be. If I run the .reg file on the target PC then it will edit the registry, so the process is stopping after the .reg is copied to the correct location, and when psexec is called. I am running the batch file w/elevated priv's. I might install psexec on the target to see if that will fix it. Otherwise, it is a holiday (sort of) enjoy your day off. This can wait until Monday. I just have to work today... thanks so much
You only need psexec on the helpdesk machine; that's what it's there for. And you can just add "-accepteula" to the psexec command line: psexec.exe \\%RemoteComputer% -accepteula reg.exe import "%RemoteFolder%"
What is Windows Update actually doing to that key; is it really changing all of those settings, or deleting them, or what exactly happens?
OK, I got it to work... I think there is a problem with the very last word in the script.. "remotefolder" / I am not sure, but this script works...

@echo off
setlocal
set RegFile=\\SomeServer\SomeShare\test.reg
set RemoteFolder=C:\logon
set /p RemoteComputer=Enter the computer name:
if "%RemoteComputer%"=="" goto :eof
copy "%RegFile%" "\\%RemoteComputer%\%RemoteFolder::=$%"
psexec.exe \\%RemoteComputer% reg.exe import "c:\logon\FixRightFaxRegKey.reg"

I have to spell out where the actual .reg file is. I think "RemoteFolder" defines where the .reg is, but maybe not which one it is... I am a newbie at scripts, so.... Thnaks!!!
I've requested that this question be closed as follows:

Accepted answer: 0 points for stoneyrok's comment #a39302059

for the following reason:

Very fast response, great communication. Works through troubleshooting with you. Has a true technical curiosity and is a great scriptor...
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
The poster used my comment, but created a Close Request for his own comment.
The poster initially created a close request (http:#a39302764) to accept his own comment, http:#a39302059, which is based on my first comment http:#a39299255. The initial script indeed contained an error, which has been fixed in http:#a39302754 without having to hard code the path in the psexec command line.
In other words: I recommend (B), accept http:#a39302754.
This worked out, and thank you very much! You rock man...