简体   繁体   中英

How to run powershell quietly from registry key?

I've added an option to copy a proper UNC path to the context menu of all directories via PowerShell.

Edit:

I didn't mention that I'm actually using two different keys: One to copy the UNC of the current directory, and one to copy it from a different directory. I didn't think it would make a difference, but it does.

End Edit

Currently, the key value is as follows:

powershell.exe -WindowStyle Hidden -Command . <path I have to censor>\Save-To-Clipboard.ps1 \"%L%\"

Expected behaviour:
The PowerShell script is run quietly.

Actual behaviour:
A PowerShell Window pops up and closes itself.

The same thing happens with cmd. I've tried using a VBS wrapper as well, but it needs the current path as an argument, which I can't figure out how to do. Simply putting it after the filename as you would in the command line results in the error:

This file does not have an app associated with it for performing this action. Please install an app or, if one is already installed, create an association in the Default Apps settings page.

Key value here:

<path I have to censor>\ClunkyWrapper.vbs \"%L%\"

Admittedly, this is my first time running a command from a registry key, and I can't seem to find any resources about this topic. (I might just not know what exactly to google for.) So I would be thankful for more general information on how to run commands from registry keys as well.

Okay, I found a way. First of all, apparently whether you need to use %L% or %V% depends on the key. I can't tell you why, unfortunately. That solves the error message of the VBA script, but it still wouldn't run like this. So I then used wscript.exe, and it finally worked.

wscript.exe <secret path>\ClunkyWrapper.vbs "%V%"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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