简体   繁体   中英

PowerShell script working as File Explorer extension

I have written a GUI app in PowerShell. It has one parameter.

At the beginning of the script I have:

param (
    [string]$Path
)

Before the Form appears, I fill in a control with $Path :

$Form.Add_Load({
    $txtSourceFile.Text = $Path
})

When I run the script interactively in PowerShell it seems to be working as expected. The txtSourceFile control is filled in with the argument from the command line.

.\ghead.ps1 -Path C:\src\data\ghead.ps1

However, when I run this as a File Explorer extension, it does not appear to receive the argument from the command line. The registry setting for the command is:

C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.EXE C:\\Users\\lit\\bin\\ghead.ps1 -Path %1

There is no error message. It simply does not fill in the $txtSourceFile.Text field. Am I missing something obvious? How can I get this to work?

The question suggested as a duplicate does not deal with running as a Windows File Explorer extension. I am already using the param() technique.

The core of the problem was an extraneous character in the Users directory name which was not presented in the question. The OP probably needs new glasses glued to his face so that he can see better and not go without them.

C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.EXE -Command C:\Users\pwatson\bin\ghead.ps1 -Path

The final registry entry turned out to be:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -WindowStyle Hidden -Command \\ASERVER\D$\Install\Utilities\ghead.ps1 -Path %1

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