复制为 Windows 上下文菜单中的路径

发布于 2024-09-02 19:28:50 字数 85 浏览 11 评论 0原文

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

I'm trying to implement "Copy as path" option in windows context menu ,which copies current file or folder path to clip board
instead of installing a software for this , i would like to implement it my self. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

战皆罪 2024-09-09 19:28:50

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

Windows Registry Editor Version 5.00

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

; hex(2) below deciphers as:
; "%windir%\System32\cmd.exe" /D /C <NUL (SET /P VAR="%1")|"%windir%\System32\clip.exe"
[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path No Quotes]
@="Copy Path"
"Icon"="imageres.dll,-5302"
"Position"="Middle"
"Extended"=-
"SeparatorBefore"=""

[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path No Quotes\command]
@=hex(2):22,00,25,00,77,00,69,00,6E,00,64,00,69,00,\
  72,00,25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
  63,00,6D,00,64,00,2E,00,65,00,78,00,65,00,22,00,20,00,2F,00,44,00,20,00,\
  2F,00,43,00,20,00,3C,00,4E,00,55,00,4C,00,20,00,28,00,53,00,45,00,54,00,\
  20,00,2F,00,50,00,20,00,56,00,41,00,52,00,3D,00,22,00,25,00,31,00,22,00,\
  29,00,7C,00,22,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,25,00,5C,00,\
  53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,63,00,6C,00,69,00,\
  70,00,2E,00,65,00,78,00,65,00,22,00,00,00

; hex(2) below deciphers as:
; "%windir%\System32\cmd.exe" /D /C <NUL (SET /P VAR="%V")|"%windir%\System32\clip.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path No Quotes]
@="Copy Path"
"Icon"="imageres.dll,-5302"
"Position"="Middle"
"Extended"=-
"SeparatorBefore"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path No Quotes\command]
@=hex(2):22,00,25,00,77,00,69,00,6E,00,64,00,69,00,\
  72,00,25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
  63,00,6D,00,64,00,2E,00,65,00,78,00,65,00,22,00,20,00,2F,00,44,00,20,00,\
  2F,00,43,00,20,00,3C,00,4E,00,55,00,4C,00,20,00,28,00,53,00,45,00,54,00,\
  20,00,2F,00,50,00,20,00,56,00,41,00,52,00,3D,00,22,00,25,00,56,00,22,00,\
  29,00,7C,00,22,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,25,00,5C,00,\
  53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,63,00,6C,00,69,00,\
  70,00,2E,00,65,00,78,00,65,00,22,00,00,00

; "%windir%\System32\cmd.exe" /D /C <NUL (SET /P VAR="%1")|"%windir%\System32\clip.exe"
[HKEY_CLASSES_ROOT\Drive\shell\Copy Path No Quotes]
@="Copy Path"
"Icon"="imageres.dll,-5302"
"Position"="Middle"
"Extended"=-
"SeparatorBefore"=""

[HKEY_CLASSES_ROOT\Drive\shell\Copy Path No Quotes\command]
@=hex(2):22,00,25,00,77,00,69,00,6E,00,64,00,69,00,\
  72,00,25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
  63,00,6D,00,64,00,2E,00,65,00,78,00,65,00,22,00,20,00,2F,00,44,00,20,00,\
  2F,00,43,00,20,00,3C,00,4E,00,55,00,4C,00,20,00,28,00,53,00,45,00,54,00,\
  20,00,2F,00,50,00,20,00,56,00,41,00,52,00,3D,00,22,00,25,00,31,00,22,00,\
  29,00,7C,00,22,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,25,00,5C,00,\
  53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,63,00,6C,00,69,00,\
  70,00,2E,00,65,00,78,00,65,00,22,00,00,00

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

; hex(2) below deciphers as:
; "%windir%\System32\cmd.exe" /D /C <NUL (SET /P VAR=""%1"")|"%windir%\System32\clip.exe"
[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path With Quotes]
@="Copy Path Quotes"
"Icon"="imageres.dll,-5302"
"Position"="Middle"
"Extended"=-
"SeparatorAfter"=""

[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path With Quotes\command]
@=hex(2):22,00,25,00,77,00,69,00,6E,00,64,00,69,00,\
  72,00,25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
  63,00,6D,00,64,00,2E,00,65,00,78,00,65,00,22,00,20,00,2F,00,44,00,20,00,\
  2F,00,43,00,20,00,3C,00,4E,00,55,00,4C,00,20,00,28,00,53,00,45,00,54,00,\
  20,00,2F,00,50,00,20,00,56,00,41,00,52,00,3D,00,22,00,22,00,25,00,31,00,\
  22,00,22,00,29,00,7C,00,22,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,\
  25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,63,00,\
  6C,00,69,00,70,00,2E,00,65,00,78,00,65,00,22,00,00,00

; hex(2) below deciphers as:
; "%windir%\System32\cmd.exe" /D /C <NUL (SET /P VAR=""%V"")|"%windir%\System32\clip.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path With Quotes]
@="Copy Path Quotes"
"Icon"="imageres.dll,-5302"
"Position"="Middle"
"Extended"=-
"SeparatorAfter"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path With Quotes\command]
@=hex(2):22,00,25,00,77,00,69,00,6E,00,64,00,69,00,\
  72,00,25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
  63,00,6D,00,64,00,2E,00,65,00,78,00,65,00,22,00,20,00,2F,00,44,00,20,00,\
  2F,00,43,00,20,00,3C,00,4E,00,55,00,4C,00,20,00,28,00,53,00,45,00,54,00,\
  20,00,2F,00,50,00,20,00,56,00,41,00,52,00,3D,00,22,00,22,00,25,00,56,00,\
  22,00,22,00,29,00,7C,00,22,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,\
  25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,63,00,\
  6C,00,69,00,70,00,2E,00,65,00,78,00,65,00,22,00,00,00

; "%windir%\System32\cmd.exe" /D /C <NUL (SET /P VAR=""%1"")|"%windir%\System32\clip.exe"
[HKEY_CLASSES_ROOT\Drive\shell\Copy Path With Quotes]
@="Copy Path Quotes"
"Icon"="imageres.dll,-5302"
"Position"="Middle"
"Extended"=-
"SeparatorAfter"=""

[HKEY_CLASSES_ROOT\Drive\shell\Copy Path With Quotes\command]
@=hex(2):22,00,25,00,77,00,69,00,6E,00,64,00,69,00,\
  72,00,25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
  63,00,6D,00,64,00,2E,00,65,00,78,00,65,00,22,00,20,00,2F,00,44,00,20,00,\
  2F,00,43,00,20,00,3C,00,4E,00,55,00,4C,00,20,00,28,00,53,00,45,00,54,00,\
  20,00,2F,00,50,00,20,00,56,00,41,00,52,00,3D,00,22,00,22,00,25,00,31,00,\
  22,00,22,00,29,00,7C,00,22,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,\
  25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,63,00,\
  6C,00,69,00,70,00,2E,00,65,00,78,00,65,00,22,00,00,00


Save this with a .reg extension and run the file as an administrator to add Copy as Path to the Windows context menu.

Windows Registry Editor Version 5.00

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

; hex(2) below deciphers as:
; "%windir%\System32\cmd.exe" /D /C <NUL (SET /P VAR="%1")|"%windir%\System32\clip.exe"
[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path No Quotes]
@="Copy Path"
"Icon"="imageres.dll,-5302"
"Position"="Middle"
"Extended"=-
"SeparatorBefore"=""

[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path No Quotes\command]
@=hex(2):22,00,25,00,77,00,69,00,6E,00,64,00,69,00,\
  72,00,25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
  63,00,6D,00,64,00,2E,00,65,00,78,00,65,00,22,00,20,00,2F,00,44,00,20,00,\
  2F,00,43,00,20,00,3C,00,4E,00,55,00,4C,00,20,00,28,00,53,00,45,00,54,00,\
  20,00,2F,00,50,00,20,00,56,00,41,00,52,00,3D,00,22,00,25,00,31,00,22,00,\
  29,00,7C,00,22,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,25,00,5C,00,\
  53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,63,00,6C,00,69,00,\
  70,00,2E,00,65,00,78,00,65,00,22,00,00,00

; hex(2) below deciphers as:
; "%windir%\System32\cmd.exe" /D /C <NUL (SET /P VAR="%V")|"%windir%\System32\clip.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path No Quotes]
@="Copy Path"
"Icon"="imageres.dll,-5302"
"Position"="Middle"
"Extended"=-
"SeparatorBefore"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path No Quotes\command]
@=hex(2):22,00,25,00,77,00,69,00,6E,00,64,00,69,00,\
  72,00,25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
  63,00,6D,00,64,00,2E,00,65,00,78,00,65,00,22,00,20,00,2F,00,44,00,20,00,\
  2F,00,43,00,20,00,3C,00,4E,00,55,00,4C,00,20,00,28,00,53,00,45,00,54,00,\
  20,00,2F,00,50,00,20,00,56,00,41,00,52,00,3D,00,22,00,25,00,56,00,22,00,\
  29,00,7C,00,22,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,25,00,5C,00,\
  53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,63,00,6C,00,69,00,\
  70,00,2E,00,65,00,78,00,65,00,22,00,00,00

; "%windir%\System32\cmd.exe" /D /C <NUL (SET /P VAR="%1")|"%windir%\System32\clip.exe"
[HKEY_CLASSES_ROOT\Drive\shell\Copy Path No Quotes]
@="Copy Path"
"Icon"="imageres.dll,-5302"
"Position"="Middle"
"Extended"=-
"SeparatorBefore"=""

[HKEY_CLASSES_ROOT\Drive\shell\Copy Path No Quotes\command]
@=hex(2):22,00,25,00,77,00,69,00,6E,00,64,00,69,00,\
  72,00,25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
  63,00,6D,00,64,00,2E,00,65,00,78,00,65,00,22,00,20,00,2F,00,44,00,20,00,\
  2F,00,43,00,20,00,3C,00,4E,00,55,00,4C,00,20,00,28,00,53,00,45,00,54,00,\
  20,00,2F,00,50,00,20,00,56,00,41,00,52,00,3D,00,22,00,25,00,31,00,22,00,\
  29,00,7C,00,22,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,25,00,5C,00,\
  53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,63,00,6C,00,69,00,\
  70,00,2E,00,65,00,78,00,65,00,22,00,00,00

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

; hex(2) below deciphers as:
; "%windir%\System32\cmd.exe" /D /C <NUL (SET /P VAR=""%1"")|"%windir%\System32\clip.exe"
[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path With Quotes]
@="Copy Path Quotes"
"Icon"="imageres.dll,-5302"
"Position"="Middle"
"Extended"=-
"SeparatorAfter"=""

[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Copy Path With Quotes\command]
@=hex(2):22,00,25,00,77,00,69,00,6E,00,64,00,69,00,\
  72,00,25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
  63,00,6D,00,64,00,2E,00,65,00,78,00,65,00,22,00,20,00,2F,00,44,00,20,00,\
  2F,00,43,00,20,00,3C,00,4E,00,55,00,4C,00,20,00,28,00,53,00,45,00,54,00,\
  20,00,2F,00,50,00,20,00,56,00,41,00,52,00,3D,00,22,00,22,00,25,00,31,00,\
  22,00,22,00,29,00,7C,00,22,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,\
  25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,63,00,\
  6C,00,69,00,70,00,2E,00,65,00,78,00,65,00,22,00,00,00

; hex(2) below deciphers as:
; "%windir%\System32\cmd.exe" /D /C <NUL (SET /P VAR=""%V"")|"%windir%\System32\clip.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path With Quotes]
@="Copy Path Quotes"
"Icon"="imageres.dll,-5302"
"Position"="Middle"
"Extended"=-
"SeparatorAfter"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Path With Quotes\command]
@=hex(2):22,00,25,00,77,00,69,00,6E,00,64,00,69,00,\
  72,00,25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
  63,00,6D,00,64,00,2E,00,65,00,78,00,65,00,22,00,20,00,2F,00,44,00,20,00,\
  2F,00,43,00,20,00,3C,00,4E,00,55,00,4C,00,20,00,28,00,53,00,45,00,54,00,\
  20,00,2F,00,50,00,20,00,56,00,41,00,52,00,3D,00,22,00,22,00,25,00,56,00,\
  22,00,22,00,29,00,7C,00,22,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,\
  25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,63,00,\
  6C,00,69,00,70,00,2E,00,65,00,78,00,65,00,22,00,00,00

; "%windir%\System32\cmd.exe" /D /C <NUL (SET /P VAR=""%1"")|"%windir%\System32\clip.exe"
[HKEY_CLASSES_ROOT\Drive\shell\Copy Path With Quotes]
@="Copy Path Quotes"
"Icon"="imageres.dll,-5302"
"Position"="Middle"
"Extended"=-
"SeparatorAfter"=""

[HKEY_CLASSES_ROOT\Drive\shell\Copy Path With Quotes\command]
@=hex(2):22,00,25,00,77,00,69,00,6E,00,64,00,69,00,\
  72,00,25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
  63,00,6D,00,64,00,2E,00,65,00,78,00,65,00,22,00,20,00,2F,00,44,00,20,00,\
  2F,00,43,00,20,00,3C,00,4E,00,55,00,4C,00,20,00,28,00,53,00,45,00,54,00,\
  20,00,2F,00,50,00,20,00,56,00,41,00,52,00,3D,00,22,00,22,00,25,00,31,00,\
  22,00,22,00,29,00,7C,00,22,00,25,00,77,00,69,00,6E,00,64,00,69,00,72,00,\
  25,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,63,00,\
  6C,00,69,00,70,00,2E,00,65,00,78,00,65,00,22,00,00,00


无远思近则忧 2024-09-09 19:28:50

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

You can add a link to the context menu by fiddling with the File Types dialog, or using the registry. In the registry, the path is HKEY_CLASSES_ROOT\*\shell. Add a key under that named "Copy as path", and a key under that named "command". Change command's default string value to "c:\your-program.exe %1", and when the user selects "Copy as path" it will run your executable with that path as the argument. Now your executable just needs to write the path passed in to it to the clipboard

享受孤独 2024-09-09 19:28:50

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

有关该主题的官方文档可在 MSDN 上找到。有关此主题的具体文章是创建上下文菜单处理程序

You will need to write your own shell namespace extension. A sample on how to do that using C# is available here. There is many examples on how to do that in C++ on web too.

The official documentation on the topic is available at MSDN. A specific article on this topic is Creating Context Menu Handlers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文