【发布时间】:2020-05-04 18:32:18
【问题描述】:
我正在尝试使用 PowerShell 在默认文本编辑器中打开非 txt 文件(在本例中为 hosts 文件)。
看到this Reddit post 后我取得了一些进展,但$txt_editor 结果总是返回 Notepad.exe,即使 Notepad++ 是我的 txt 文件的默认编辑器。
$hosts_file = "$env:windir\System32\drivers\etc\hosts"
$txt_editor = ((Get-ItemProperty -Path 'Registry::HKEY_CLASSES_ROOT\txtfile\shell\open\command').'(Default)').trimend(" %1")
Start-Process -FilePath $txt_editor -Verb Runas -ArgumentList $hosts_file
这也会返回 Notepad.exe:
(Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\OpenWithList' -Name a).a
如果我在注册表编辑器中查看上述位置,我确实看到 Notepad++ 列出了键 d,但我不知道如何仅查看注册表键来判断默认文本编辑器是什么,因为我在 Reddit 上看到的两个解决方案都不起作用。
我使用的是 Windows 10,我正在寻找的解决方案将返回实际的默认文本编辑器文件位置,以便它可以用来打开如上所示的文件。
【问题讨论】:
标签: powershell registry