PS - List ALL Installed Programs using HKLM & HKCU.

Page 1 of 5 123 ... LastLast

  1. Posts : 18,034
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #1

    PS - List ALL Installed Programs using HKLM & HKCU.


    Yesterday, I was tidying up some of my files, and came across a .bat file that I use to output ALL the installed Programs which uses the REG Keys HKLM & HKCU. It works brilliantly, but the code is long and complicated. It involves compiling and exporting the data to a temp file, sorting it, and then importing it and creating the output file [ I can post if needed ].

    Anyway, I thought that I would try and find a simpler PowerShell solution, which I have, sort of.

    This outputs ALL the required data [ exactly the same as my .bat file ], but, in three sections. Each section has a heading followed by the data. What I would like for it to do is to just output ONE heading, sorted uniquely alphabetically. As I said, I have been working on this yesterday and today and I am stumped.

    Code:
    
    $Destination_File = 'C:\Users\System-Admin\Desktop\123.txt'
    if (Test-Path $Destination_File) {Remove-Item $Destination_File}
    
    Get-ChildItem -Path HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Sort-Object -Property DisplayName | Select-Object -Property DisplayName, DisplayVersion, InstallLocation | Out-file -FilePath $Destination_File
    Get-ChildItem -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Sort-Object -Property DisplayName | Select-Object -Property DisplayName, DisplayVersion, InstallLocation | Out-file -FilePath $Destination_File -Append
    Get-ChildItem -Path HKLM:Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Sort-Object -Property DisplayName | Select-Object -Property DisplayName, DisplayVersion, InstallLocation | Out-file -FilePath $Destination_File -Append
    
    (Get-Content -Path $Destination_File).Length -2 | Out-file -FilePath $Destination_File -Append
    
    
    
    
    

    The .Length -2 is obviously to ignore the TWO lines Title.

    Thanks.

    I have made some progress, I have just found | Format-Table -Hide. Now to try and Sort and ADD the Title back.
    Last edited by Paul Black; 29 Oct 2021 at 09:20.
      My Computer


  2. Posts : 16,962
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #2

    Paul,

    You might prefer the well-structured csv outputs of
    NirSoft UninstallView

    My routine use of it is
    Code:
    …\UninstallView.exe /scomma ...\%ComputerName%-InstalledAppsList.csv
    using suitable paths

    Additional comments in
    my ditty about NirSoft UninstallView - TenForums
    List installed Windows applications offline (from external drive) - NirSoft


    All the best,
    Denis
      My Computer


  3. Posts : 18,034
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #3

    Thanks for the reply Denis, it is appreciated.

    I did look at that Thread yesterday to try and find the solution. I want to particularly do the way I have specified above as this is part of a bigger project.

      My Computer


  4. Posts : 16,962
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #4

    Might using PS's ability to output to csv be manipulated to achieve a single list for you?
    Export-Csv - SS64
    Export-Csv - MSDocs - this includes mention of the Append switch
    Use PowerShell to Append CSV Files Easily - Scripting Blog

    Best of luck,
    Denis
      My Computer


  5. Posts : 18,034
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #5

    Hello Denis,

    Yes, I did look at .csv, but it did NOT output in the format I am after, I would ideally like the data aligned in columns.
    Last edited by Paul Black; 29 Oct 2021 at 11:32.
      My Computer


  6. Posts : 16,962
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #6

    Paul Black said:
    I would ideally like the data aligned in columns.
    This is a fairly typical csv file [column widths dragged to display text better].
    PS - List ALL Installed Programs using HKLM & HKCU.-csvexample.jpg
    created by commands such as
    powershell.exe Get-WindowsDriver -Online ^| Export-CSV '%BackupFolder%\DismDriversList-3rdParty.csv' -NoTypeInformation
    powershell.exe Get-WindowsDriver -Online -all ^| Export-CSV '%BackupFolder%\DismDriversList-All.csv' -NoTypeInformation
    [these particular PS commands are controlled by a batch file because that is also doing a number of other jobs]

    Isn't that the sort of structure you are after, then?

    Denis
      My Computer


  7. Posts : 18,034
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #7

    Thanks again Denis,

    Try3 said:
    Isn't that the sort of structure you are after, then?
    I will need to look at that again obviously, as long as I can get the output columns lined up in Notepad.

    I have put this together, but I will probably change it as I am probably making this far more complicated that it needs to be. The only thing missing is a couple of the entries are NOT aligned to the rest in columns . . .

    Code:
    
    @echo off
    setlocal EnableDelayedExpansion
    set "Params=%*"
    cd /d "%~dp0" && ( if exist "%Temp%\getadmin.vbs" del "%Temp%\getadmin.vbs") && fsutil dirty query %SystemDrive% 1>nul 2>nul || ( echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %Params%", "", "runas", 1 >> "%Temp%\getadmin.vbs" && "%Temp%\getadmin.vbs" && Exit /b)
    %WinDir%\system32\reg.exe query "HKU\S-1-5-19" 1>nul 2>nul || ( echo. & echo  ERROR: This Batch file MUST be run in an ELEVATED cmd prompt [ Administrator ] & echo. & echo         Right-click the Batch file and click ^<Run as Administrator^>. & echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit )
    
    set "DT=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
    for /f "usebackq tokens=3" %%X in (`Reg Query "%DT%" /V Desktop`) do (set Desktop=%%X)
    for /f "usebackq delims=" %%X in (`echo "%Desktop%"`) do (set "Desktop=%%X")
    set "Desktop=%Desktop:~1,-1%"
    
    set "OUT=%UserProfile%\Desktop\OUT.txt"
    set "OFN=%UserProfile%\Desktop\123.txt"
    if exist %OUT% (del /f /q %OUT% >nul 2>&1)
    if exist %OFN% (del /f /q %OFN% >nul 2>&1)
    
    echo. & echo  Processing . . .
                  PowerShell $Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size(250,250)
    >> %OUT%      PowerShell Get-ChildItem -Path HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall ^| Get-ItemProperty ^| Sort-Object -Property DisplayName ^| Select-Object -Property DisplayName, DisplayVersion, InstallLocation
    >> %OUT%      PowerShell Get-ChildItem -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Uninstall ^| Get-ItemProperty ^| Sort-Object -Property DisplayName ^| Select-Object -Property DisplayName, DisplayVersion, InstallLocation ^| Format-Table -Hide
    >> %OUT%      PowerShell Get-ChildItem -Path HKLM:Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall  ^| Get-ItemProperty ^| Sort-Object -Property DisplayName ^| Select-Object -Property DisplayName, DisplayVersion, InstallLocation ^| Format-Table -Hide
                  findstr /rc:"[^ <tab>]" %OUT% >> %OFN%
                  del %OUT%
            echo  Processing Complete.
    echo. & echo ^>Press ANY key to Exit . . . & pause >nul & Exit
    
    
    Last edited by Paul Black; 29 Oct 2021 at 11:32.
      My Computer


  8. Posts : 16,962
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #8

    Paul Black said:
    as long as I can get the output columns lined up in Notepad
    csv files cannot do that. This is what the same csv file looks like in Notepad.
    PS - List ALL Installed Programs using HKLM &amp; HKCU.-csv-notepad.png

    Denis
      My Computer


  9. Posts : 18,034
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #9

    Try3 said:
    csv files cannot do that. This is what the same csv file looks like in Notepad.
    PS - List ALL Installed Programs using HKLM &amp; HKCU.-csv-notepad.png

    Yes, I want the output in Notepad, that is why I ignored .csv yesterday when I looked. In the above code I have managed to get the Titles, so the ONLY problem now is that a couple of the output entries are NOT aligned with the others. I might have to live with that.
      My Computer


  10. Posts : 16,962
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #10

    Pauul,

    I thought I'd give your script a whirl.

    It correctly finds the Desktop path up to the line set "Desktop=%Desktop:~1,-1%"
    but the line set "OUT=%UserProfile%\Desktop\OUT.txt" ignores that and sets the Desktop path to its default path [and the same for the following OFN line]
    so I think two lines need to be replaced with
    Code:
    set "OUT=%Desktop%\OUT.txt"
    set "OFN=%Desktop%\123.txt"
    [I'm never comfortable with variable names that are the same as names used elsewhere within Windows]

    It then runs to completion and gives me a text output -
    PS - List ALL Installed Programs using HKLM &amp; HKCU.-123-denisresults.png
    - It is not lined up in Notepad into columns but is clearly a 3 column list
    - There are some repetitions in the list, such as
    PS - List ALL Installed Programs using HKLM &amp; HKCU.-repetition.png

    Denis
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 22:58.
Find Us




Windows 10 Forums