简体   繁体   English

将动态参数传递给 CMD 并保存命令

[英]Passing dynamic parameters to CMD and saving the command

I would like to password-encrypt folders (and ideally also files — individual and multiple ones) pre-selected in the Windows 10 file explorer via the context menu.我想通过上下文菜单对 Windows 10 文件资源管理器中预先选择的文件夹(理想情况下还有文件 - 单个和多个文件)进行密码加密。 Unfortunately I couldn't find any program capable of it.不幸的是,我找不到任何能够做到这一点的程序。 If by chance you know one please do tell, that would be the perfect solution.如果你碰巧认识一个请告诉我,那将是完美的解决方案。

Otherwise, this tool is the closest to the described requirements that I could find.否则,这个工具最接近我能找到的描述的要求。 However, it requires to navigate to the desired folder manually via their own navigation window, so it doesn't work just by right clicking a folder in the Windows file explorer.但是,它需要通过自己的导航 window 手动导航到所需的文件夹,因此仅通过右键单击 Windows 文件资源管理器中的文件夹不起作用。 But I have an idea for a workaround: that tool supports the CMD command line so that a folder could be encrypted like so:但我有一个解决方法的想法:该工具支持 CMD 命令行,以便可以像这样加密文件夹:

"C:\Program Files (x86)\EncryptOnClick\EncryptOnClick.exe" -p password -e "C:\Users\username\Documents\Test" 

If I could make password and the Test -folder dynamic variables and store the CMD-command or make it a batch-, AHK-, VBscript-, Powershell- or whatever script I could attach that script to the registry key HKEY_CLASSES_ROOT\Directory\shell key as described here , right, and it would appear in the context menu upon right-clicking a folder in the file explorer.如果我可以制作passwordTest文件夹动态变量并存储 CMD 命令或使其成为批处理、AHK-、VBscript-、Powershell- 或任何脚本,我可以将该脚本附加到注册表项 HKEY_CLASSES_ROOT\Directory\shell此处描述的键,对,它会在右键单击文件资源管理器中的文件夹时出现在上下文菜单中。

But how do I make password (and I should be prompted to input one of my choice) and the Test -folder (which I already right-clicked in the file explorer) dynamic variables and store that whole thing as a script that I can attach to HKEY_CLASSES_ROOT\Directory\shell, so that the script appears in the context menu?但是我如何制作password (并且应该提示我输入我的选择之一)和Test文件夹(我已经在文件资源管理器中右键单击)动态变量并将整个内容存储为我可以附加的脚本到 HKEY_CLASSES_ROOT\Directory\shell,让脚本出现在上下文菜单中?

Many thanks in advance!提前谢谢了!

Without trying it out myself, I'm pretty confident you can do it with AHK as easily as this:无需亲自尝试,我很有信心您可以像这样轻松地使用 AHK 做到这一点:

;the folder/file path should be here
path := A_Args[1]
InputBox, pass, % "Encrypt File/Folder", % "Enter a password", HIDE
command := """C:\Program Files (x86)\EncryptOnClick\EncryptOnClick.exe"" -p """ pass """ -e """ path """"

;verify that the command we're about to launch is correct
;obviously you'd remove this from the real final version of the script
MsgBox, 4, % "Check command", % "Is this command correct?`n" command
IfMsgBox, Yes
    Run, % command

Added a test messagebox in there so you can see if it works as expected.在其中添加了一个测试消息框,以便您查看它是否按预期工作。
Related documentation links:相关文档链接:
A_Args , InputBox , Escaping quotes and MsgBox A_ArgsInputBoxEscaping 报价MsgBox

See call /?call /? for how parameters are handled.关于如何处理参数。 Use set /p to get user input (if you don't like the big black box for input, you have to switch to another language (or use the help of one); cmd is command line based):使用set /p获取用户输入(如果您不喜欢输入的大黑框,则必须切换到另一种语言(或使用一种语言的帮助); cmd是基于命令行的):

@echo off
set /p "pass=Enter password: "
"C:\Program Files (x86)\EncryptOnClick\EncryptOnClick.exe" -p %pass% -e "%~1"

Put a shortcut to that script in %APPDATA%\Microsoft\Windows\SendTo\将该脚本的快捷方式放在%APPDATA%\Microsoft\Windows\SendTo\

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM