3

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?

8 Answers8

3

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?

sblair
  • 12,757
JWN
  • 31
1

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

Greg Hewgill
  • 5,619
1

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

1

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

0

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

0

Try this from an elevated CMD prompt:

reg import file.reg
paradroid
  • 23,297
0

It doesn't work with the relative path as others suggested. This is a problem if you don't know what the path will be to package a batch file to also import a registry key(s).

For reference the path is c:\windows\system32 for an elevated command prompt.

As long as the .reg file is in the same folder as the batch file you can simply add %~dp0 in front of the file name and it will use fill in the direct path to the batch file.

regedit.exe /s %~dp0registryfile.reg
NyFL
  • 11
0

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 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
Jan Doggen
  • 4,657