Windows 8 Regedit requires absolute paths passed in for registry files

1

1

I was building a set of batch scripts for our automatic build/test system which runs across different operating systems to set some conditions for the different environments and I noticed that Windows 8 seems to handle regedit.exe command line arguments differently than Windows XP through 7.

I was running the command:

regedit.exe /s relative_path\registry_settings.reg

This worked correctly until we got to a Windows 8 node, at which point it didn't emit any errors but moved on as if it worked without making any of the registry changes. (and then my entire test suite failed and scared me)

To get Windows 8 to work I had to use an absolute path as such:

regedit.exe /s \absolute_path\registry_settings.reg

Is this a deliberate change from Microsoft, or is it likely that there is an environment setting affecting this? Is there a better solution than using an absolute path (which is brittle and will require more future maintenance)?

BlargleMonster

Posted 2014-06-17T19:03:01.867

Reputation: 125

1Had your bat script "cd" to the directory where the relative path could be picked up? – Kinnectus – 2014-06-17T19:05:03.983

As I think @BigChris is hinting towards - are you sure your Windows 8 setup is dropping you into the same path that Windows 7 was? – Ƭᴇcʜιᴇ007 – 2014-06-17T19:10:03.767

1Are you working with doesn't architectures also? Perhaps your Windows 7 is x86 and Win 8 x64? Program Files and Program Files (x86)? – Kinnectus – 2014-06-17T19:14:31.307

Answers

2

In a batch script, you can use %~dp0 to represent the directory that contains the running batch script. So if you had files at the following locations:

C:\scripts\script.bat
C:\scripts\relative_path\registry_settings.reg

you could write this in script.bat:

regedit.exe /s "%~dp0relative_path\registry_settings.reg"

and get all the benefits of relative paths and still work on Windows 8.

William Jackson

Posted 2014-06-17T19:03:01.867

Reputation: 7 646

This sounds like a great option, I'll give it a try and then accept the answer if it works. – BlargleMonster – 2014-06-19T15:36:14.697

Just so long as the bat script is in the same folder that contains the relative paths it is attempting to read from...? – Kinnectus – 2014-06-17T19:13:00.527

@BigChris I updated my answer to make it more explicit. – William Jackson – 2014-06-17T19:16:24.140