Run a batch file at folder's context menu

2019-07-08 10:45发布

I'd like to run this batch file (setenv.cmd) when I right click on any folder:

@echo off
SET CPLUS_INCLUDE_PATH=C:\mingw32\include;C:\mingw32\lib\gcc\mingw32\4.9.2\include;
SET PATH=%PATH%;C:\Archivos de programa\7-Zip;C:\Archivos de programa\WinRAR;C:\usr\bin;C:\msys\1.0\bin;C:\gtk2\bin
SET PKG_CONFIG_PATH=C:\gtk2\lib\pkgconfig;C:\usr\lib\pkgconfig
@echo on

I setuped my registry from this page, with the "prompt here". My question is how to open the console window from the selected directory and run my batch file?

1条回答
Animai°情兽
2楼-- · 2019-07-08 11:06

Use &. On Windows 8.1:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\cmdDD]
@="CMD + setenv"

[HKEY_CLASSES_ROOT\Directory\shell\cmdDD\command]
@="cmd.exe /s /k pushd \"%V\"&call \"D:\\full\\path\\to\\setenv.cmd\" \"%V\""

;

Note that all inner " double quotes and \ reverse slashes in the data are escaped with a \ backslash. In fact, data are as follows:

==>reg query HKEY_CLASSES_ROOT\Directory\shell\cmdDD\command

HKEY_CLASSES_ROOT\Directory\shell\cmdDD\command
    (Default)    REG_SZ    cmd.exe /s /k pushd "%V"&call "D:\full\path\to\setenv.cmd" "%V"

Edit: cmd.exe /s /k pushd "%V"&call "D:\full\path\to\setenv.cmd" should suffice. An additional (trailing) "%V" is merely a remainder residue of my debugging practice (@echo %1 in the batch to ensure it works).

Resources (required reading):

查看更多
登录 后发表回答