Solved Run PS1 files (double click) on Windows 11


ChristianL

Member
Local time
4:10 AM
Posts
2
OS
Windows 11 Education
Hello,
On Windows 10 I was able to modify the file association by using the following command :

Set-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command" -Name '(Default)' -Value '"C:\Program Files\PowerShell\7\pwsh.exe" -noLogo -ExecutionPolicy bypass -file "%1"'

This command no longer works on Windows 11 because the registry location does not exist. I need a way to make PS scripts to run with a double click and the solution must be in a form of a command , No GUI solutions please.

Thanks
 
Windows Build/Version
21H2

My Computer

System One

  • OS
    Windows 11 Education
    Computer type
    Laptop
    Manufacturer/Model
    Dell
    CPU
    Intel i9-10885H 2.4Ghz
    Motherboard
    Dell
    Memory
    32 GB
    Graphics Card(s)
    GTX 1650 TI
    Monitor(s) Displays
    2
    Screen Resolution
    3840x2400
    Hard Drives
    SSD - 1Tb
    Browser
    Edge
    Antivirus
    Sophos
Example. Running PS_ise.
Any .ps1 file -> Properties: Change PS_ise

# .ps1
If (!(Test-Path "HKCR:\PS_ise.ps1\DefaultIcon")) {
New-Item -Path "HKCR:\PS_ise.ps1\DefaultIcon" -Force
}
Set-ItemProperty -Path "HKCR:\PS_ise.ps1\DefaultIcon" -Name "(default)" -Type ExpandString -Value "$ExtLibraryIcons,-12" -Force
Set-ItemProperty -Path "HKCR:\.ps1" -Name "(default)" -Type String -Value "PS_ise.ps1" -Force
Set-ItemProperty -Path "HKCR:\PS_ise.ps1" -Name "(default)" -Type String -Value "File .ps1" -Force
If (!(Test-Path "HKCR:\PS_ise.ps1\Shell\Open\Command")) {
New-Item -Path "HKCR:\PS_ise.ps1\Shell\Open\Command" -Force
}
Set-ItemProperty -Path "HKCR:\PS_ise.ps1\Shell\Open" -Name "FriendlyAppName" -Type String -Value "PS_ise" -Force
Set-ItemProperty -Path "HKCR:\PS_ise.ps1\Shell\Open\Command" -Name "(default)" -Type String -Value '"C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe" "%1"'-Force
 

My Computer

System One

  • OS
    Microsoft Windows 11 Home
    Computer type
    PC/Desktop
    Manufacturer/Model
    MSI MS-7D98
    CPU
    Intel Core i5-13490F
    Motherboard
    MSI B760 GAMING PLUS WIFI
    Memory
    2 x 16 Patriot Memory (PDP Systems) PSD516G560081
    Graphics Card(s)
    GIGABYTE GeForce RTX 4070 WINDFORCE OC 12G (GV-N4070WF3OC-12GD)
    Sound Card
    Bluetooth Аудио
    Monitor(s) Displays
    INNOCN 15K1F
    Screen Resolution
    1920 x 1080
    Hard Drives
    WD_BLACK SN770 250GB
    KINGSTON SNV2S1000G (ELFK0S.6)
    PSU
    Thermaltake Toughpower GF3 1000W
    Case
    CG560 - DeepCool
    Cooling
    ID-COOLING SE-224-XTS / 2 x 140Mm Fan - rear and top; 3 x 120Mm - front
    Keyboard
    Corsair K70 RGB TKL
    Mouse
    Corsair KATAR PRO XT
    Internet Speed
    100 Mbps
    Browser
    Firefox
    Antivirus
    Microsoft Defender Antivirus
    Other Info
    https://www.userbenchmark.com/UserRun/66553205
Thanks abactuon !! - I modified your script and everything is working as needed
 

My Computer

System One

  • OS
    Windows 11 Education
    Computer type
    Laptop
    Manufacturer/Model
    Dell
    CPU
    Intel i9-10885H 2.4Ghz
    Motherboard
    Dell
    Memory
    32 GB
    Graphics Card(s)
    GTX 1650 TI
    Monitor(s) Displays
    2
    Screen Resolution
    3840x2400
    Hard Drives
    SSD - 1Tb
    Browser
    Edge
    Antivirus
    Sophos
Hi - sorry to necro a thread, but running into this with machines that need to run by default from group policy. We've tried every registry entry we can think of and are going to test the script above. Nothing works on Windows 11 except manually setting it in control panel, which we can't do. These machines have to run a powershell created by another application dedicated to the user who badged in to function correctly. Has anyone else weaponized this for widescale deployment?
 

My Computer

System One

  • OS
    Windows 11 Insider Developer Preview
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom
    CPU
    7950x3D
    Motherboard
    ASRock x670e Taichi
    Memory
    64GB G.skill 6000Mhz CL32 @ 6400Mhz CL30
    Graphics Card(s)
    Nvidia Founders Edition RTX 4090
    Sound Card
    Scarlett Solo 3rd Gen
    Screen Resolution
    1x4k@160hz and 2x1440p@165Hz
    Hard Drives
    8xDell SAS 800GB SSD, 1x4TB Samsung 990 Pro, 1x2TB Samsung 980 Pro, 2x2TB Samsung 980 Pro, 4x980GB Sandisk SATA SSD
    PSU
    Seasonic Prime Platinum 1200W
    Case
    Thermaltake Tower 900 White
    Cooling
    2x480 and 1x560 Rad custom loop
    Keyboard
    Glorius GMMK Pro
    Mouse
    Razer Naga Pro V2
    Internet Speed
    Symmetrical 1Gbps Fiber Optic on Palo Alto PA440
    Browser
    Microsoft Edge Developer Preview
Download SetUserFTA, and create a new FTA (file type association). Double-clicking on *.ps1 will auto-run from Explorer.

Code:
ftype Microsoft.PowerShellScript.1="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -ExecutionPolicy Bypass -f "%1"
SetUserFTA.exe .ps1 Microsoft.PowerShellScript.1

If you prefer PS 7:
Code:
ftype Microsoft.PowerShellScript.1="C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -ExecutionPolicy Bypass -f "%1"
 

My Computer

System One

  • OS
    Windows 7
Back
Top Bottom