Copy as path in windows context menu

2019-03-07 01:18发布

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?

3条回答
我想做一个坏孩纸
2楼-- · 2019-03-07 01:45
Windows Registry Editor Version 5.00

;Scripted by Jeff Hollis
;(https://stackoverflow.com/users/10572786/slyfox1186)
;To edit this script manually using hex(2) you must utilize OTConvertIt.exe
;(http://www.geekstogo.com/forum/files/file/404-otconvertit)
;or equivalent to decipher hex(2) into "Windows Registry Editor Version 5.00" aka ASCII or vice versa.
;REG_EXPAND_SZ is the only type of registry entry that will work entirely for this
;particular type of context menu item.

;%%%%%%%%%%%%%%%% 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
查看更多
女痞
3楼-- · 2019-03-07 01:46

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.

查看更多
爷、活的狠高调
4楼-- · 2019-03-07 01:48

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

查看更多
登录 后发表回答