Bespoke Right-Click Cascading Menu Command Fails in DOpus but Works in Explorer

I have made a custom menu to run scripts when clicking an empty area in a folder (i.e. not on a file). However in DOpus the scripts are failing because the current directory is set to C:\Windows\System32, regardless of the current location, whereas in Windows Explorer the current directory is set to the actual directory that the UI is displaying.

Here's a simplified version of my .reg file


[HKEY_CLASSES_ROOT\Directory\Background\shell\MyCascadingMenu]
"MUIVerb"="MyCascadingMenu"

[HKEY_CLASSES_ROOT\Directory\Background\shell\MyCascadingMenu]
"SubCommands"="MyTool"

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\MyTool]
@="MyTool"
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\MyTool\command]
@="CMD /k \"CD\""

When I right click in C:\temp\temp_project and click MyCascadingMenu>MyTool in DOpus I get

C:\Windows\system32

C:\Windows\system32>

When I right click in C:\temp\temp_project and click MyCascadingMenu>MyTool in Windows Explorer I get

C:\temp\temp_project

C:\temp\temp_project>

Is there a way to fix this?

That's intentional, for improved security. It avoids DLL planting exploits if you run a program which doesn't take steps to avoid loading DLLs from the current directory (which might be files downloaded from the internet).

You can change it to work like File Explorer via Preferences / Miscellaneous / Advanced: [Compatibility] def_func_cd_sourcedir, but it'd be much better to make your menu item independent of the current directory.

Using the current directory doesn't really make sense anyway, as there can be situations where a menu is run on files from multiple locations. Since you're passed the full path to each file, you don't need to use the current directory in most cases.

1 Like

Hi Leo,
I'm not running the script on a file, but on the empty background of a folder. The script essentially copies files from a central location to the directory of its first argument. If no argument is supplied then it assumes the working dir is the argument. I don't know of any other way to get a right click menu to function in the way intended that works for both DOpus and Explorer users.

%V will get you that in this context.

E.g. CMD /k "CD /D %V" as the command which is run.

Should work the same in Opus and Explorer.

That's a gem - thank you :slight_smile:

1 Like