2

im working on a personal project that opens other programs and currently I am using a text file where I have to manually enter the path to the exe file like this

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

I wanted to know is there a way to get a list of all the locations of exe files? I know that how to get a list of the installed programs and somewhat of the file path using

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* 

but it doesn't really give the whole path.

AdminOfThings
  • 23,946
  • 4
  • 17
  • 27
  • If you just want to crawl your entire hard drive and get a list of all the `.exe` files, there are several options for that. If you instead only want those applications that are "installed" into Windows, for example, I suspect you'd want to read them from the Registry. – Zephyr Feb 17 '19 at 01:57
  • i'd rather look at the set path(setting a path is language agnostic): https://stackoverflow.com/questions/9546324/adding-directory-to-path-environment-variable-in-windows – kai Feb 17 '19 at 02:01
  • I recommend reading [Where is “START” searching for executables?](https://stackoverflow.com/a/27386403/3074564) – Mofi Feb 17 '19 at 09:41

2 Answers2

3

Programmers use Internet Explorer, a key programming component on Windows. So it is silly to use non windows programs.

Start chrome

Programs listed at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths can be started in the Windows' shell by typing their name. In a console you can force executing via the shell by using start.

Note call all files something.exe but the actual file doesn't need to be an exe.

So

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

when typing win it will open win.ini.


Path

Adding a common console program to the path allows you just to type the name.

From my PasteBin account https://pastebin.com/YKEmChkc this file

This batch file adds the folder the batch file is in to the user's path for future command prompts

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

In a command prompt type path /?, set /?, setx /?, ftype /?, assoc /?.

Also see the default search that CreateProcess uses.

1.The directory from which the application loaded.

2.The current directory for the parent process.

3.The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.

  1. The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.

5.The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.

6.The directories that are listed in the PATH environment variable. Note that this function does not search the per-application path specified by the App Paths registry key. To include this per-application path in the search sequence, use the ShellExecute function.


Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste). Type for table format

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

or in a form format

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

It will create a html file on the desktop.

Note

This is not a full list. This is only products installed with Windows Installer. There is no feature for everything.

However as I said in my previous post nearly everything is listed in the registry.

So to see it in a command prompt

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

or in a file

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

To see it in notepad in a different format

Click Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type Regedit and navigate to

 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

Right click the Uninstall key and choose Export. If you save as a reg file (there is also text file, they are slightly different text formats) you need to right click the file and choose Edit to view it.

To view Windows Updates

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

.

Noodles
  • 194
  • 1
  • 4
  • This does help a little bit but, the registry here only has a small handful of apps compared to HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* – BimBim SalaBim Feb 17 '19 at 02:25
  • 1
    Important ones and you can add your own as my post explained. – Noodles Feb 17 '19 at 02:29
  • `Dir c:\*.exe /a /b` will list all programs on a hard disk. This info has useless and useful information mixed up.. – Noodles Feb 17 '19 at 03:08
1

this code is for powershell, but the idea applies to other programming lingos. [grin] it reads the 32/64 bit uninstall keys for the local machine/all users & current user reg keys.

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
    }

called thus ...

Get-LD_InstalledSoftware -DisplayName *chrome*

... you get the following back ...

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

that output can be filtered easily to include only the desired level of detail.

Lee_Dailey
  • 7,292
  • 2
  • 22
  • 26