Reply To: How to use PowerShell to switch default app (from pre-determined list)?
by
JosephMack26
·
about 1 year, 7 months ago
In reply to How to use PowerShell to switch default app (from pre-determined list)?
You can use PowerShell to switch the default app from a predetermined list by using the Set-ItemProperty cmdlet to modify the registry keys that control file associations. Here’s an example script to set the default app for a particular file type:
$extension = “.txt” # Change this to the file extension you want to modify
$appPath = “C:\Windows\System32\notepad.exe” # Change this to the path of the app you want to set as default
# Set the default app for the file extension
Set-ItemProperty -Path “HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$extension\UserChoice” -Name “ProgId” -Value “Applications\$appPath”
# Refresh the shell to apply the changes
$null = (New-Object -ComObject Shell.Application).Namespace(0).ParseName(“file.$extension”).InvokeVerb(“OpenWith”)
Note: This script modifies the registry, so be sure to back up your registry or create a system restore point before running it.
In this script, replace the $extension variable with the file extension you want to modify (e.g., “.txt”, “.docx”, etc.). Replace the $appPath variable with the path to the app you want to set as default (e.g., “C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE” for Microsoft Word).
The script uses the Set-ItemProperty cmdlet to modify the “ProgId” value of the file extension’s UserChoice key in the registry. This value specifies the default app for the file type. The script then uses the New-Object cmdlet to create a Shell.Application object and refreshes the shell to apply the changes. This ensures that the changes take effect immediately.
Once you run this script, the specified app should become the default app for the file type you specified.