![](/img/trans.png)
[英]How do you get a dictionary of all installed programs on a windows system in python?
[英]How do you list the Scopes of all your installed programs on Windows 10? Preferably through PowerShell
有什么方法可以檢查我安裝的程序的 scope 嗎? 我想知道某些程序是否僅適用於 CurrentUser,或者它們是否可供 AllUsers 使用。 最好通過 PowerShell,但我想不一定是這樣。
使用Get-Command
和Where-Object
cmdlet在當前用戶的主目錄樹之外的目錄中查找 PATH 中的所有可執行文件(位於$env:PATH
中列出的目錄中) :
# Finds all executables in $env:PATH that are *not* located in the
# current user's home-directory tree.
Get-Command -Type Application |
Where-Object { -not $_.Path.StartsWith($HOME, 'OrdinalIgnoreCase') }
要詢問給定可執行文件名稱的問題,請使用計算屬性:
# For the given executable names, outputs [pscustomobject] instances
# containing each executable's full path and a flag that indicates
# whether the executable's directory is located in the
# current user's home-directory tree.
Get-Command -Type Application foo, bar |
Select-Object Path,
@{ Name='CurrentUserOnly'; Expression={ $_.Path.StartsWith($HOME, 'OrdinalIgnoreCase') } }
如果要包含無法直接從 shell (其目錄不在$env:PATH
中)調用但可以通過start
( cmd.exe
)/ Start-Process
(PowerShell)/通過GUI的Run
對話框( WinKey-R ) ,如excel.exe
:
# Finds all executables in $env:PATH *and* those that can be launched
# via cmd /c start / Start-Process, which are *not* located in the
# current user's home-directory tree.
# Lists full paths only.
@(Get-Command -Type Application).Path +
(Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths').
ForEach({ if ($val = $_.GetValue('') -replace '"') { $val } }) |
Where-Object { -not $_.StartsWith($HOME, 'OrdinalIgnoreCase') }
注意:不幸的是, Get-Package
-IncludeWindowsInstaller
不是一個選項,因為雖然它確實列出了已安裝的應用程序,但它似乎:
不能與 Windows PowerShell 中的-Scope CurrentUser
或-Scope AllUsers
結合使用; PowerShell (Core) 7+至少默認不支持-IncludeWindowsInstaller
/ -ProviderName -ProviderName Programs
。
也不返回有關已安裝程序的可執行路徑的信息。
我正在嘗試 get-package 的 -scope 參數,但這不適用於應用程序。 這是獲取它的另一種方法(Powershell 5.1)。 這些每用戶應用程序往往是管理員的禍根。
get-package | ? fastpackagereference -match hklm # 130 items
get-package | ? fastpackagereference -match hkcu | ft -a
Name Version Source ProviderName
---- ------- ------ ------------
Cisco Webex Meetings 41.5.4 Programs
Amazon Kindle 1.31.0.60170 Programs
f.lux Programs
Microsoft OneDrive 21.073.0411.0002 Programs
Slack 4.16.1 Programs
Microsoft Teams 1.4.00.4167 Programs
Microsoft Visual Studio Code (User) 1.55.2 Programs
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.