I am trying input this command line into context menu so when I right-click on the USB drive, that drive letter would pass into the .ps1 script and run commands using that driveletter. This script requires -Verb RunAS, but my version does not work.
The registry is
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Drive\shell\PassOnUSBLetter]
@="PassOnUSBLetter"
"HasLUAShield"=""
"Icon"="powershell.exe"
[HKEY_CLASSES_ROOT\Drive\shell\PassOnUSBLetter\command]
@="powershell.exe -ExecutionPolicy Bypass -File \"C:\\Users\\Tim\\USB.ps1\" %1 -verb runas"
.ps1 script is just
$driveLetter = $args[0]
Write-Host Drive Letter used: $driveLetter
# do more later on
when sharing any code please remember to format it as code.
You can use the “Preformatted Text” button from the toolbar.
Guide to Posting Code
1 Like
thanks for editing everything.
I haven’t done this before so I’m not sure what the constraints are for adding commands, but what is the %1
variable represent? I’m also not sure about the -verb runas
part as that’s not a Powershell parameter or a CMD parameter that i’m familiar with.
Start-Process powershell -Verb RunAs
-Verb RunAs makes it Run As Administrator. The %1 represents the path, right-clicked
ok, I see now that Start-Process has the -Verb RunAs
parameter, but your original code isn’t using Start-Process.
From what I can see the value you put in the “Command” key is going to be processed as a command, not PowerShell. If you need RunAs you might have to try the -Command parameter of powershell.exe and see if you can do a Start-Process in there with the -Verb parameter and point to your script.