codepleb
codepleb

Reputation: 10571

Executing a regfile from within .bat

I have the following code in the batch-file:

@echo on
regedit.exe /S abc.reg

If I run it, I get an error.

I searched the google for this and found nothing. Can someone help me please? I tried: - removing /S (the I can read (of course) the errormessage - Run the file as administrator (I'm admin per default)

I am using windows 8. The erros message: "Cannot import C:\users....abc.reg". Error opening the file. There may be a disk or a file system error.

Both Files are in the same folder. enter image description here

Upvotes: 1

Views: 7581

Answers (4)

Knuckle-Dragger
Knuckle-Dragger

Reputation: 7046

Right click on aix2_mm.bat and select "Run As Administrator", you will get a full screen UAC prompt that you must agree with, then it will work.

If you don't see 'Run As Administrator' as an option, hold the shift key prior to right clicking.

and it wouldn't hurt to make your batch more portable. The %~dp0 parameter will expand to the full path to ABC.reg if it's in the same folder as the .bat file.

@echo on
regedit.exe /S "%~dp0abc.reg"

Upvotes: 2

IlPADlI
IlPADlI

Reputation: 2033

Be careful the working directory

My bat file always has the code on first line

cd /d %~dp0

It can safely change current directory to your bat file directory

Upvotes: 1

codepleb
codepleb

Reputation: 10571

The problem was, that I handled the %~dp0 in a false way. %~dp0 stands for the default path, but you don't have to set a backslash after it!

If you want to run a .reg file in the same folder as the .bat file, just write it like this:

@echo on
REGEDIT /S "%~dp0ABC.reg"

This will run the file ABC.reg in the same folder.

If you wan't to run something in a subfolder, you have to do it like this:

@echo on
REGEDIT /S "%~dp0SUBFOLDER\ABC.reg"

The brackets ("") are only needed, if there are whitespaces in the pathname.

Upvotes: 3

Sunny
Sunny

Reputation: 8302

Much easier way is run it as a Scheduled task.

In this way you can get your batch file to run as admin without annoying password prompts.

For more valuable information, please read here...

http://forums.whirlpool.net.au/archive/2037875

http://social.technet.microsoft.com/Forums/systemcenter/en-US/be854b0a-5d41-4b03-9a84-8fe79732f33c/run-bat-file-to-call-reg-file-in-sccm?forum=configmgrswdist

http://www.myitforum.com/articles/1/view.asp?id=12036

Upvotes: 2

Related Questions