0

我正在尝试在 Windows 上下文菜单中实现“复制为路径”选项,它将当前文件或文件夹路径复制到剪贴板,而不是为此安装软件,我想自己实现它。有什么建议么?

4

3 回答 3

2

使用扩展名保存此.reg文件并以管理员身份运行该文件,以将“复制为路径”添加到 Windows 上下文菜单。

Windows Registry Editor Version 5.00

;%%%%%%%%%%%%%%%% COPY PATH NO QUOTES %%%%%%%%%%%%%%%%

;hex(2) below deciphers as:
;cmd /c <nul (set/p var="%1")|clip
[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path No Quotes]
"Icon"="imageres.dll,-5302"
[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path No Quotes\command]
@=hex(2):63,00,6D,00,64,00,20,00,2F,00,63,00,20,00,\
    3C,00,6E,00,75,00,6C,00,20,00,28,00,73,00,65,00,74,00,2F,00,70,00,20,00,\
    76,00,61,00,72,00,3D,00,22,00,25,00,31,00,22,00,29,00,7C,00,63,00,6C,00,\
    69,00,70,00,00,00

;hex(2) below deciphers as:
;cmd /c <nul (set/p var="%V")| clip
[HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path No Quotes]
"Icon"="imageres.dll,-5302"
[HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path No Quotes\command]
@=hex(2):63,00,6D,00,64,00,20,00,2F,00,63,00,20,00,\
    3C,00,6E,00,75,00,6C,00,20,00,28,00,73,00,65,00,74,00,2F,00,70,00,20,00,\
    76,00,61,00,72,00,3D,00,22,00,25,00,56,00,22,00,29,00,7C,00,20,00,63,00,\
    6C,00,69,00,70,00,00,00

;%%%%%%%%%%%%%%%% COPY PATH WITH QUOTES %%%%%%%%%%%%%%%%

;hex(2) below deciphers as:
;cmd /c <nul echo|set/p var=""%1""|clip
[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path With Quotes]
"Icon"="imageres.dll,-5302"
[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path With Quotes\command]
@=hex(2):63,00,6D,00,64,00,20,00,2F,00,63,00,20,00,\
    3C,00,6E,00,75,00,6C,00,20,00,65,00,63,00,68,00,6F,00,7C,00,73,00,65,00,\
    74,00,2F,00,70,00,20,00,76,00,61,00,72,00,3D,00,22,00,22,00,25,00,31,00,\
    22,00,22,00,7C,00,63,00,6C,00,69,00,70,00,00,00

;hex(2) below deciphers as:
;cmd /c <nul echo|set/p var=""%V""|clip
[HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path With Quotes]
"Icon"="imageres.dll,-5302"
[HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path With Quotes\command]
@=hex(2):63,00,6D,00,64,00,20,00,2F,00,63,00,20,00,\
    3C,00,6E,00,75,00,6C,00,20,00,65,00,63,00,68,00,6F,00,7C,00,73,00,65,00,\
    74,00,2F,00,70,00,20,00,76,00,61,00,72,00,3D,00,22,00,22,00,25,00,56,00,\
        22,00,22,00,7C,00,63,00,6C,00,69,00,70,00,00,00

要删除上述更改,请参见下文:

Windows Registry Editor Version 5.00

; REMOVE COPY PATH CONTEXT MENU ENTRIES

[-HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path No Quotes]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path No Quotes]
[-HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path With Quotes]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path With Quotes]

于 2018-12-03T06:05:06.240 回答
1

您可以通过摆弄File Types对话框或使用注册表来添加到上下文菜单的链接。在注册表中,路径是HKEY_CLASSES_ROOT\*\shell. 在名为“复制为路径”下添加一个键,并在名为“命令”下添加一个键。将命令的默认字符串值更改为“c:\your-program.exe %1”,当用户选择“复制为路径”时,它将以该路径作为参数运行您的可执行文件。现在您的可执行文件只需要将传递给它的路径写入剪贴板

于 2010-05-25T05:44:17.353 回答
1

您将需要编写自己的shell 命名空间扩展此处提供了有关如何使用 C# 执行此操作的示例。在网络上也有很多关于如何在 C++ 中执行此操作的示例。

MSDN 上提供了有关该主题的官方文档。有关此主题的特定文章是创建上下文菜单处理程序

于 2010-05-25T07:06:25.080 回答