3
1
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?
I got the exact same error but in both RegEdit and the batch file. It turns out that either regedit or the UAC account elevation can't handle local folders that are mounted to a drive letter with
subst D: "C:\FolderName"
. RunningD:\test.reg
fails while the full pathC:\FolderName\test.reg
works fine. – Lilienthal – 2017-07-26T10:55:54.993Btw, it's Windows 7 Ultimate (64-bit) in a VMWare image. – Brian T Hannan – 2011-01-04T22:12:06.130
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 – 2011-01-04T22:33:14.313
It's hard to believe that no one else is having this same problem. – Brian T Hannan – 2011-01-05T18:51:01.087
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 – 2011-01-10T16:48:34.050
@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. – user1686 – 2011-05-27T11:06:50.883@Brian: (Use
cd /d "%~dp0"
to force to the batch file's location.) Besides, whilecmd
does have many quirks, it doesn't touch filenames you give to other commands - it's entirely up toreg
how to treat the file named in, for example,reg import foo\bar\baz.reg
. – user1686 – 2011-05-27T11:27:27.910grawity was correct, when you open a command-prompt normally, it defaults to your user directory, but when you run it as administrator, it defaults to the system directory (
– Synetech – 2013-10-06T05:00:56.783\Windows
).