utils
utils copied to clipboard
Don't assume Notepad is installed, instead get the default app for .txt files to edit the script.
Changes
- Instead of assuming Notepad is installed by default, grab the default app for .txt files to edit the script:
try {
[string] $Class = ((Get-Item "Registry::HKEY_CLASSES_ROOT\.txt\OpenWithProgids") | Select-Object -First 1).Property
[string] $Path = "Registry::HKEY_CLASSES_ROOT\$Class\shell\open\command"
[string] $Command = (Get-ItemPropertyValue -Path $Path -Name "(Default)")
Invoke-Expression "& $($Command.Replace("%1", ($argv | Select-Object -First 1)))"
}
catch {}
best would be to use https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/invoke-item?view=powershell-5.1
also try to do formatting in separate commits, or even better respect the coding style
best would be to use https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/invoke-item?view=powershell-5.1
also try to do formatting in separate commits, or even better respect the coding style
Reverted any formatting changes, now the script just includes the required code.
Also Invoke-Item won't work, as the documentation says it executes the default action on a specified item. In the case of batch scripts, it will just start a new instance of it.
What we want to use are Object Verbs unfortunately the edit verb for batch files launches Notepad by default because of this its better to use the default application for .txt files.
no catch?
on windows sandbox