Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a .bat file that makes a call to a .reg file (something like: regedit mytest.reg). I run the .bat file as administrator but I get an error: "Cannot import mytest.reg: Error opening the file. There may be a disk or file system error."

However, if I open RegEdit (as administrator) first then File >> Import >> mytest.reg ... it successfully runs.

Any ideas?

share|improve this question

migrated from stackoverflow.com Jan 5 '11 at 8:28

This question came from our site for professional and enthusiast programmers.

Btw, it's Windows 7 Ultimate (64-bit) in a VMWare image. –  Brian T Hannan Jan 4 '11 at 22:12
It also works if I open cmd.exe as administrator then kick off the .bat file. For some reason it seems like the Run as administrator for a .bat file doesn't work. –  Brian T Hannan Jan 4 '11 at 22:33
It's hard to believe that no one else is having this same problem. –  Brian T Hannan Jan 5 '11 at 18:51
It turns out that if you have a .bat file and relative paths in it then it doesn't know how to use them properly. But if you only put in absolute paths in the .bat file then it works ... bug in Windows 7 batch files? –  Brian T Hannan Jan 10 '11 at 16:48
@Brian: Paths are relative to the "current directory", which may simply be different when you use "Run as administrator". Add a cd to see what the current directory is. –  grawity May 27 '11 at 11:06
show 2 more comments

7 Answers 7

Is the .reg file on a network volume? Local administrators cannot normally read files from across a network.

share|improve this answer
Nope, it's local and on the Desktop ... both .reg and .bat –  Brian T Hannan Jan 4 '11 at 22:09
Network volume was the issue for me. It would be nice if Windows would tell you that. –  Scott Lundberg Jun 28 '13 at 20:22
add comment

It works for me in a simple test, but I have to answer UAC-related prompts when the batchfile runs.

Have you customized your UAC settings? Maybe when you run the batch file things are configured to not elevate (or even ask to elevate) so it fails.

But regedit elevates when it loads (regardless of UAC settings, I think).

share|improve this answer
I turned off UAC and still didn't work for me. –  Brian T Hannan Jan 4 '11 at 22:28
add comment

Had the same problem. Once you accept running under elevated permissions, the "root" of the elevated session does not have the same relative location for the actual command.

If you specify an absolute address for the file it should work.

Now the $.42 question... what is the current directory for the elevated session in which the command is running?

share|improve this answer
add comment

I had the exact same problem and error message.. I could not get my REG file to from my batch file on my Win7 Pro 64 bit machine. Finally got it to work by puttin quatation marks around the REG file.. (EXAMPLE)

c:\windows\regedit.exe /s "C:\Windows\Enable DTS Login Script.reg"

Hope this is helpful

share|improve this answer
Part of the reason yours wasn't working is because you had spaces in the filename. –  MBraedley Apr 10 '13 at 12:43
add comment

try using the /C switch "regedit /C myfile.reg"

share|improve this answer
Nope, didn't work. –  Brian T Hannan Jan 4 '11 at 22:27
add comment

Try this from an elevated CMD prompt:

reg import file.reg
share|improve this answer
add comment

It doesn't seem to work with the relative path as others suggested.

This is what worked for me:

Simply add %~dp0 in front of the file name and it will use fill in the direct path to the batch file. So as long as the .reg file is in the same folder as the batch file you are good to go.

For example regedit.exe /s %~dp0registryfile.reg

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.