Link to home
Start Free TrialLog in
Avatar of IN_DOE
IN_DOE

asked on

How to change a registry key on multiple machines via psexec?

Ok, I have looked at multiple other EE threads but thus far had no luck applying what I have seen to my organization. Here is what I am trying to do...

I need to edit a registry value located at HKLM\SYSTEM\CurrentControlSet\Services\USBSTOR on a couple hundred desktops running Windows XP. My instinct was to export a key with the desired values and then use a script to execute the exported .reg file remotely via psexec since I have no way to force users to log off and log back in for a login script to run the file. I can go to a remote computer and execute my script which contains only a single line:

regedit /s \\absolute.path\to\file.reg

Path edited, obviously, but you get the point. If I sit at a remote computer and execute this .bat file, the registry value is changed as desired. However, if I run the same .bat file on the same computer via psexec, psexec returns with an error code 0 (so, no error) but the registry value does not change. The psexec command as I'm running it is thus:

psexec \\computername.my.domain -c mybatfile.bat

I have tried entering other switches into the psexec command, such as -s to run the .bat file in the System account, but the end result remains the same. No change is made to the registry on the remote machine despite no error being produced. The only way I have successfully been able to us psexec to execute this script is when I include the -i switch, running it so that it interacts with the desktop on the remote machine, but that still requires user input which is what I'm trying to avoid.

Can anyone tell me what I'm missing here?
Avatar of Joseph Daly
Joseph Daly
Flag of United States of America image

Have you tried just running psexec with psexec \\computername.my.domain regedit /s \\absolute.path\to\file.reg

You may not need the batch file at all.
Here you go...

PathToPSExec\psexec -d -i -c "@PathToTxtFile\computers.txt" regedit.exe /s "\\UNCPathToRegFile\file.reg"

Open in new window

Avatar of IN_DOE
IN_DOE

ASKER

I have, and I get the same result. It returns with Error Code 0 but no value is changed in the remote computer's registry.
Make sure when you are using my command, there is only one computername(or IP) per line...Also, make sure that the user you are running PSExec as has local admin rights on the workstations.
There's actually no need for heavy artillery like psexec here.
You can use reg.exe to do that remotely (btw: a login script wouldn't work because users are not allowed to write to HKLM; you'd need a startup script):
reg.exe add \\<MachineName>\HKLM\SYSTEM\CurrentControlSet\Services\USBSTOR /v "the Value name" /d "the Data" /f

To do that for a list of machines ("machines.txt", one name per line), you can run it from the command line like this:
for /f %a in ('type machines.txt') do @reg.exe add \\%a\HKLM\SYSTEM\CurrentControlSet\Services\USBSTOR /v "Value name" /d "Data" /f

Or, as a batch script, double up on the percent signs:
@echo off
for /f %%a in ('type machines.txt') do reg.exe add \\%%a\HKLM\SYSTEM\CurrentControlSet\Services\USBSTOR /v "Value name" /d "Data" /f
Avatar of IN_DOE

ASKER

nappy_d: When I try to run it with the switches you've provided I get a response from psexec that "regedit.exe was started on computername.my.domain with process ID 872." but still no love on the change actually occurring.
ASKER CERTIFIED SOLUTION
Avatar of nevesis
nevesis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you are trying to disable usb removable devices you can use this ADM file from petri.

http://www.petri.co.il/disable_writing_to_usb_disks_in_xp_sp2_with_gpo.htm
Avatar of IN_DOE

ASKER

Awesome. This was exactly what I was looking for
Avatar of IN_DOE

ASKER

nevesis provided the first solution that worked for me and that I understood immediately. Marking many other comments as helpful, though. Thanks all!