Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add current folder to reg file

Tags:

I have the following reg file

    Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Run script]
@="Run &script"

[HKEY_CLASSES_ROOT\*\shell\Run script\command]
@="\"C:\\Users\\teodora\\Desktop\\test.bat\" \"%1\""

How can I add the path of the current folder instead of using C:\Users... ? I know how to do this in a .bat file but for a .reg one doesn't work in the same way.

like image 327
Alexandra Giurgiteanu Avatar asked Apr 02 '18 11:04

Alexandra Giurgiteanu


2 Answers

You don't use a reg file, you use reg.exe with the Add option:

Here's a complete batch file which should do it all for you:

@Reg Add "HKCU\Software\Classes\*\Shell\RunScript" /VE /D "Run &Script" /F >Nul
@Reg Add "HKCU\Software\Classes\*\Shell\RunScript\command" /VE /D "\"%CD%\test.bat\" \"%%L\"" /F >Nul

Note that this uses the 'current directory' as requested. Adjust %CD% accordingly if you no longer want that.

like image 91
Compo Avatar answered Sep 22 '22 13:09

Compo


Use the variable %W which is the working directory.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Run script]
@="Run &script"

[HKEY_CURRENT_USER\Software\Classes\*\shell\run script\command]
@="cmd /c \"\"%W\\test.bat\" \"%1\"\""

Using %W instead of a literal absolute path seems to require cmd /c as a prefix to work for me.

like image 21
michael_heath Avatar answered Sep 20 '22 13:09

michael_heath