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)?

3
  • 1
    Had your bat script "cd" to the directory where the relative path could be picked up?
    – Kinnectus
    Jun 17, 2014 at 19:05
  • 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? Jun 17, 2014 at 19:10
  • 1
    Are you working with doesn't architectures also? Perhaps your Windows 7 is x86 and Win 8 x64? Program Files and Program Files (x86)?
    – Kinnectus
    Jun 17, 2014 at 19:14

1 Answer 1

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.

3
  • Just so long as the bat script is in the same folder that contains the relative paths it is attempting to read from...?
    – Kinnectus
    Jun 17, 2014 at 19:13
  • @BigChris I updated my answer to make it more explicit. Jun 17, 2014 at 19:16
  • This sounds like a great option, I'll give it a try and then accept the answer if it works. Jun 19, 2014 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .