有没有办法获取所有已安装程序的安装路径?

时间:2019-02-17 01:55:27

标签: windows shell powershell cmd registry

我正在处理一个打开其他程序的个人项目,目前我正在使用一个文本文件,在该文件中,我必须手动输入exe文件的路径,例如

C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe 

我想知道有没有一种方法可以获取exe文件所有位置的列表?我知道如何使用

获取已安装程序的列表以及某些文件路径
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* 

但是它并没有给出完整的路径。

2 个答案:

答案 0 :(得分:2)

程序员使用Internet Explorer(Windows上的关键编程组件)。因此,使用非Windows程序很愚蠢。

Start chrome

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths处列出的程序可以通过在Windows外壳程序中键入名称来启动。在控制台中,您可以使用start通过外壳强制执行。

请注意调用所有文件something.exe,但实际文件不必是exe。

所以

Win.exe
    @="C:\Windows\win.ini

键入win时,它将打开win.ini


路径

将通用控制台程序添加到路径中,只需键入名称即可。

从我的PasteBin帐户https://pastebin.com/YKEmChkc中获取该文件

此批处理文件将批处理文件所在的文件夹添加到用户的路径中,以供将来使用命令提示符

REM One file follows
REM _AddThisFolderToPath.bat
REM This batch file adds the folder the batch file is in to the user's path for future command prompts
REM If the folder is already in the user's path the command is ignored
Setx path "%path%;%~dp0"
REM Optional add to the current path setting
REM Set path "%path%;%~dp0"
Pause

在命令提示符下,键入path /?set /?setx /?ftype /?assoc /?

另请参阅CreateProcess使用的默认搜索。

  

1。从中加载应用程序的目录。

     

2。父进程的当前目录。

     

3。32位Windows系统目录。使用GetSystemDirectory函数获取此目录的路径。

     
      
  1. 16位Windows系统目录。没有获取该目录路径的函数,但会对其进行搜索。的名字   该目录是系统。
  2.   
     

5。Windows目录。使用GetWindowsDirectory函数获取此目录的路径。

     

6。PATH环境变量中列出的目录。请注意,此功能不会按应用程序路径搜索   由“应用路径”注册表项指定。包括这个   搜索顺序中的每个应用程序路径,请使用ShellExecute   功能。


开始-所有程序-附件-右键单击“命令提示符”,然后选择“以管理员身份运行”。键入(或在“命令提示符”窗口中右键单击并选择“粘贴”来复制和粘贴)。表格格式的类型

 wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:htable

或采用表单格式

 wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:hform

它将在桌面上创建一个html文件。

注意

这不是完整列表。这仅是与Windows Installer一起安装的产品。没有所有功能。

但是正如我在上一篇文章中所说的,注册表中几乎列出了所有内容。

所以要在命令提示符下看到它

  reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s

或在文件中

 reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s>"%userprofile%\desktop\WindowsUninstall.txt"

要在记事本中以其他格式查看

单击开始-所有程序-附件-右键单击命令提示符,然后选择以管理员身份运行。输入Regedit并导航到

 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

右键单击“卸载”键,然后选择“导出”。如果另存为reg文件(也有文本文件,它们的文本格式略有不同),则需要右键单击该文件,然后选择“编辑”以查看它。

要查看Windows更新

 wmic /output:"%userprofile%\desktop\WindowsUpdate.html" qfe  get /format:htable

答案 1 :(得分:1)

此代码用于powershell,但该思想适用于其他编程术语。 [ grin ]会读取local machine/all userscurrent user reg键的32/64位卸载键。

function Get-LD_InstalledSoftware
    <#
    .SYNOPSIS
        Get Installed software via the registry.

    .NOTES
        Original source ...
        Find Installed Software - Power Tips - PowerTips - IDERA Community
        - http://community.idera.com/powershell/powertips/b/tips/posts/find-installed-software

        Version
        - 2017.09.22.23.35.49 
        == added Publisher search item
        - 2018.09.21.10.04.24 
        == changed name to avoid collision with other similar code
    #>
    {
    [CmdletBinding()]
    Param
        (
        # Wildcard characters allowed - and recommended.
        [Parameter()]
        [string]
        $DisplayName = '*',

        # Wildcard characters allowed.
        [Parameter()]
        [string]
        $DisplayVersion = '*',

        # Use 'yyyyMMdd' format.
        [Parameter()]
        [string]
        $InstallDate = '*',

        # Wildcard characters allowed.
        [Parameter()]
        [string]
        $Publisher = '*',

        # Wildcard characters allowed, but normally this otta be left to the default.
        [Parameter()]
        [string]
        $UninstallString = '*'
        )

    # registry locations for installed software
    $Provider = 'Registry::'
    $All = 'HKEY_LOCAL_MACHINE\SOFTWARE'
    $Current = 'HKEY_CURRENT_USER\SOFTWARE'
    $64_32 = 'Microsoft\Windows\CurrentVersion\Uninstall\*'
    $32_on_64 = 'WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'

    $RPathAllUser = -join ($Provider, (Join-Path -Path $All -ChildPath $64_32))
    $RPathCurrentUser = -join ($Provider, (Join-Path -Path $Current -ChildPath $64_32))
    $RPathAllUser32 = -join ($Provider, (Join-Path -Path $All -ChildPath $32_on_64))
    $RPathCurrentUser32 = -join ($Provider, (Join-Path -Path $Current -ChildPath $32_on_64))

    # get all values from all 4 registry locations
    $Result = Get-ItemProperty -Path $RPathAllUser, $RPathCurrentUser, $RPathAllUser32, $RPathCurrentUser32 |
        # skip items without a DisplayName
        Where-Object DisplayName -ne $null |
        Where-Object {
            $_.DisplayName -like $DisplayName -and
            $_.DisplayVersion -like $DisplayVersion -and
            $_.InstallDate -like $InstallDate -and
            $_.Publisher -like $Publisher -and
            $_.UninstallString -like $UninstallString
            } |
        Sort-Object -Property DisplayName 

    $Result
    }

这样称呼...

Get-LD_InstalledSoftware -DisplayName *chrome*

...您将获得以下回报...

DisplayName     : Google Chrome
UninstallString : "C:\Program Files (x86)\Google\Chrome\Application\72.0.3626.109\Installer\setup.exe" --uninstall --system-level --verbose-logging
InstallLocation : C:\Program Files (x86)\Google\Chrome\Application
DisplayIcon     : C:\Program Files (x86)\Google\Chrome\Application\chrome.exe,0
NoModify        : 1
NoRepair        : 1
Publisher       : Google Inc.
Version         : 72.0.3626.109
DisplayVersion  : 72.0.3626.109
InstallDate     : 20190213
VersionMajor    : 3626
VersionMinor    : 109
PSPath          : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome
PSParentPath    : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
PSChildName     : Google Chrome
PSProvider      : Microsoft.PowerShell.Core\Registry

可以轻松过滤输出以仅包含所需的细节级别。

相关问题