Jump to content

adding right-click menu item that calls batch file


graysky

Recommended Posts

Can someone tell me how I can add a right-click menu item that will simply run a batch file in the directory I right-click? I know how to do this with a file, but not a directory.

For files, I my send to notepad tweak is as follows:

[HKEY_CLASSES_ROOT\*\Shell]

[HKEY_CLASSES_ROOT\*\Shell\Send to Notepad]

[HKEY_CLASSES_ROOT\*\Shell\Send to Notepad\Command]
@="notepad.exe %1"

In my example, I have a batch file called "dogain.bat" and I would like it to run in a whatever directory the user right-clicks and then selects the option (let's call it "do replaygain") from the pop-up menu.

Any help is appreciated!

Thanks!

Link to comment
Share on other sites


[HKEY_CURRENT_USER\Software\Classes\Folder\shell\do replaygain]
[HKEY_CURRENT_USER\Software\Classes\Folder\shell\do replaygain\command]
@="\"C:\\My Bats\\dogain.bat\" \"%1\""

Just change the location of the bat as required, and you can replace \Folder\ with \Directory\, if you prefer.

You can change the HKEY_CURRENT_USER\Software\Classes, for HKEY_LOCAL_MACHINE\SOFTWARE\Classes, if your tweak is for all users. This would be the same as HKEY_CLASSES_ROOT, but you should try to avoid directly going there; all HKLM\SOFTWARE\Classes entries are mapped to HKCR.

Edited by Yzöwl
Link to comment
Share on other sites

Firstly, thanks for the help :)

I copied your code into a "dogain.reg" file like so:

REGEDIT4

[HKEY_CURRENT_USER\Software\Classes\Folder\shell\do replaygain]
[HKEY_CURRENT_USER\Software\Classes\Folder\shell\do replaygain\command]
@="\"C:\My Bats\dogain.bat\" \"%1\""

And then merged it with my registry. (I also moved the files to c:\my bats to keep it simple.) When I looked at the resulting registry in regedit, the last line of the batch file is no where in sight... what did I do wrong?

post-14231-1113135279_thumb.jpg

Link to comment
Share on other sites

Cool... looks fine from the registry now; however when I right-click a dir and select the "do replaygain" option, a dos window opens and closes too fast for me to read the error message. I can't tell what's happening but the batch file should take a good 30-50 seconds to complete when run from commandline. Any ideas how I can add a wait or something so I can debug?

Thanks again!

Link to comment
Share on other sites

Any ideas how I can add a wait or something so I can debug?

Just add a 'pause' command at the end of the batch file, this will allow you to see any errors before the window closes.

without seeing the batch file, your problem may be to do with directories that have spaces in them, or not picking up the full path properly.

SP

Link to comment
Share on other sites

I think I found the problem: when I right click a dir anywhere in a given drive, the batch file tries to run on the root drive -- not the dir I'm rightclicking. In other words, I rightlcik e:\work and select the command from the pop-up. The result is that the batch file runs on e:\ Likewise, if I right-click d:\temp\album and select the command from the pop-up, the result is that the batch file runs on d:\

Took me a while to figure it out but that's the case... is there something wrong with the reg key syntax that wouldn't pass on the full path to the batch file?

Link to comment
Share on other sites

The problem is not in the registry entry, but in your batch file.

The batch file will very likely still be running in its own directory, i.e C:\My Bats

As a simple fix, I would just make sure that your batch is in the directory upon which you clicked. To do this the batch would probably need to start with a line something like

@echo off
CD %1

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...