5

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.

  • Possible duplicate of [What is the current directory in a batch file?](https://stackoverflow.com/questions/4419868/what-is-the-current-directory-in-a-batch-file) – Brett Holmes Apr 02 '18 at 11:47
  • @PhotographyBum I need to do this in a .reg file not in a .bat file – Alexandra Giurgiteanu Apr 02 '18 at 11:53
  • @AlexandraGiurgiteanu, my answer uses a batch file according to the tag you used. Are you telling us that despite using the `[batch-file]` tag, you don't want to use a batch file at all? – Compo Apr 03 '18 at 15:29

2 Answers2

2

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.

Compo
  • 36,585
  • 5
  • 27
  • 39
2

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.

michael_heath
  • 5,262
  • 2
  • 12
  • 22