简体   繁体   English

如何在 Powershell 中列出可执行文件名

[英]How to List Executable File Names In Powershell

I need to list all installed applications in windows.我需要在 Windows 中列出所有已安装的应用程序。 Using powershell and the following command, I can find out the name and some other details of the installed applications.使用powershell和以下命令,我可以找到已安装应用程序的名称和其他一些详细信息。

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ * | Select-Object DisplayName

What I want is to also find out the commandline of the applications so that I can run the application using that commandline .我想要的是找出应用程序的commandline ,以便我可以使用该commandline运行应用程序。 So basically I need following informations-所以基本上我需要以下信息-

  1. Name of the application申请名称
  2. Command line of the application应用程序的命令行
  3. Start an application using commandline使用命令行启动应用程序

What might be the possible solution for doing that?这样做的可能解决方案是什么?

There are an unfortunately large number of ways to interpret "applications installed" on windows.不幸的是,有很多方法可以解释 Windows 上的“已安装的应用程序”。

If you are looking for a list of programs on your path, you can use如果您正在寻找路径上的程序列表,您可以使用

Get-Command -Type Application

This list includes programs installed as part of Windows, as well as those added after that, if the installer adjusted the PATH environment variable to make the programs visible at the command line.如果安装程序调整了 PATH 环境变量以使程序在命令行中可见,则此列表包括作为 Windows 一部分安装的程序以及之后添加的程序。 The list will be big.名单会很大。

Depending on the version of PowerShell you are using, the Get-Package command may be of help.根据您使用的 PowerShell 版本, Get-Package命令可能会有所帮助。 Under PowerShell 5.1, it includes information from multiple sources, including the uninstall programs list in the registry, the windows installer (MSI) database, and information about system updates.在 PowerShell 5.1 下,它包含来自多个来源的信息,包括注册表中的卸载程序列表、Windows 安装程序 (MSI) 数据库以及有关系统更新的信息。 That list will be big too, but different from the Get-Command list.该列表也很大,但与Get-Command列表不同。

The installed program are located in other registry key:安装的程序位于其他注册表项中:

 HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

The following script get all programs and the their commandline:以下脚本获取所有程序及其命令行:

 $q="`""
 Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\*"  |
 Where-Object {$_."(default)" -ne $null} |
 Select-Object @{ expression={$_.PSChildName}; label='Program'} ,@{ expression={$q + $_."(default)" +$q}; label='CommandLine'}

Sample of output result:输出结果示例:

    Program             CommandLine                                                                  
    -------             -----------                                                                  
    7zFM.exe            "C:\Program Files (x86)\7-Zip\7zFM.exe"                                      
    AcroRd32.exe        "C:\Program Files (x86)\Adobe\Reader 9.0\Reader\AcroRd32.exe"   
    excel.exe           "C:\PROGRA~2\MICROS~1\Office12\EXCEL.EXE"    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM