Search code examples
powershellbatch-filecmdvbscriptautohotkey

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. 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. But I have an idea for a workaround: that tool supports the CMD command line so that a folder could be encrypted like so:

"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.

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?

Many thanks in advance!


Solution

  • See 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):

    @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\