Copy file on right click, to a specefic location

2019-08-03 02:04发布

问题:

I would like to add a menu item to the right click menu in Windows 7. This menu item would be called something like "Copy to temp".

When clicking that item, I would like to take the current file, on wihch I've have clicked, and copy it to a specefic location. Overwriting it if it excists.

Something like:

copy %selectedFile "c:\documents and settings\myuser\Desktop\destination_dir\"

Anyone have any ideas?

Thanks

/Christoffer

回答1:

Merge the following into your registry:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\*\shell\copyto]
@="Copy to Desktop"

[HKEY_CURRENT_USER\Software\Classes\*\shell\copyto\command]
@="cmd.exe /c copy /y \"%1\" \"C:\\Documents and Settings\\myuser\\Desktop\\destination_dir\\\""

If you want it to work for all users, it gets a little more complicated because you need a REG_EXPAND_SZ for the default value of the command subkey:

reg add "HKCR\*\shell\copyto" /v /t REG_SZ /d "Copy to Desktop" /f
reg add "HKCR\*\shell\copyto\command" /ve /t REG_EXPAND_SZ /d "%COMSPEC% /c copy /y \"%1\" \"%"USERPROFILE"%\\Desktop\\destination_dir\\\""

Of course you could also put the command in a batch script and run that script via the registry key:

@="C:\path\to\your.cmd \"%1\""

You also need a script when you want to handle auto-creation of a missing destination folder.

Either way a cmd window will be poping up briefly whenever you select the new context menu entry. To avoid that you'll have to use a different scripting language, e.g. VBScript.



标签: cmd registry