2

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.

5
  • Possible duplicate of Pass parameter from batch file to the powershell script Commented Mar 26, 2017 at 7:49
  • Don't you have to wrap this in a function and call the function to pass the parameter that way? I may be wrong but that is how I would do it. Commented Mar 26, 2017 at 13:55
  • @nkasco - What would you suggest as the registry entry to run a function inside the .ps1 file? Commented Mar 26, 2017 at 20:51
  • What will be the value of path here, can you hard code the path in registry and try ? Commented Mar 28, 2017 at 3:04
  • 1
    Can you please share how can I make an explorer shell extension in powershell? Particularly how to create registry entries which regsvr32.exe does for native DLLs? Commented Mar 22, 2022 at 5:16

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.