How can I associate a file type with a powershell script?

后端 未结 5 1141
名媛妹妹
名媛妹妹 2021-02-14 10:10

I have a very powershell script that works perfectly and does:

Param(
  [string]$fileName
) 

echo \"Woo I opened $fileName\"

When I run it on

5条回答
  •  别跟我提以往
    2021-02-14 10:35

    Use the proper tools for the job:

    cmd /c assoc .fob=foobarfile
    cmd /c ftype foobarfile=powershell.exe -File `"C:\path\to\your.ps1`" `"%1`"
    

    Note that both assoc and ftype are CMD-builtins, so you need to run them via cmd /c from PowerShell.

    For files without extension use this association:

    cmd /c assoc .=foobarfile
    

提交回复
热议问题