We help IT Professionals succeed at work.

Batch File to Edit Registry

whoam
whoam asked
on
Okay, I have a really simple script.  It runs from local storage just fine, but from a network locaiton, it fails with no error.

The batch file backup up a reg key, then calls a .reg to remove the offending key.

Having the script pause at each step reveals no errors.

Like I said, run it locally, it works, run it from a network location it silently fails.  One note, when run locally it creates a new .reg for the undo in the folder with the existing .reg below and teh existing .bat below.  From a network location it creates no new .reg.  I'm not sure if it needs a place to stick the new .reg, but I don't know how to give it a target in the script.
rem first, back up the registry key so it can later be restore.
Regedit.exe /e HCP_Protocol_Backup.reg HKEY_CLASSES_ROOT\HCP
rem pause

rem next, remove the vulnerable registry key.
Regedit.exe /s HCP.reg
rem pause

rem finally, restore the vulnerable key one the vendor patch is avaiable
rem Regedit.exe /s HCP_Protocol_Backup.reg

Open in new window

Contents of HCP.reg are as follows...

Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\HCP]

Open in new window

Comment
Watch Question

Steve AgnewSr. Systems Engineer

Commented:
My guess is that it's a permisions issue.. when you run it from a network are you doing it under your account?  Also when dealing with things like scripts you should always put the entire path in every reference to avoid things going where you don't want them to.. if you don't the default path will be used...
Sr. Systems Engineer
Commented:
oh example below, and whereever you want the files to go put their full path in to..
rem first, back up the registry key so it can later be restore.
c:\windows\system32\Regedit.exe /e HCP_Protocol_Backup.reg HKEY_CLASSES_ROOT\HCP
rem pause

rem next, remove the vulnerable registry key.
c:\windows\system32\Regedit.exe /s HCP.reg
rem pause

rem finally, restore the vulnerable key one the vendor patch is avaiable
rem Regedit.exe /s HCP_Protocol_Backup.reg

Open in new window