Inside this window, the full list of installed programmes should be displayed
Assistant
Here's a PowerShell script that creates an 800x600 window and displays the full list of installed programs on your Windows 7 machine. This script utilizes the Windows Forms library to create a graphical user interface (GUI) and queries the registry to retrieve the list of installed programs.
# Add the .NET Windows Forms assembly to create GUI elements
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Create a new form (window)
$form = New-Object System.Windows.Forms.Form
$form.Text = "Installed Programs"
$form.Size = New-Object System.Drawing.Size(800, 600)
$form.StartPosition = "CenterScreen"
# Create a DataGridView to display the list of programs
$dataGridView = New-Object System.Windows.Forms.DataGridView
$dataGridView.Dock = 'Fill'
$dataGridView.AutoSizeColumnsMode = 'Fill'
$dataGridView.ReadOnly = $true
# Function to retrieve installed programs from the registry
function Get-InstalledPrograms {
$programs = @()
# Registry paths containing uninstall information
$regPaths = @(
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
)
foreach ($path in $regPaths) {
try {
# Get all items in the uninstall registry key
$items = Get-ItemProperty $path -ErrorAction SilentlyContinue
foreach ($item in $items) {
if ($item.DisplayName) {
$program = New-Object PSObject -Property @{
Name = $item.DisplayName
Version = $item.DisplayVersion
Publisher = $item.Publisher
InstallDate = $item.InstallDate
UninstallKey = $path
}
$programs += $program
}
}
} catch {
# Handle any access exceptions silently
}
}
return $programs | Sort-Object Name
}
# Retrieve the list of installed programs
$installedPrograms = Get-InstalledPrograms
# Convert the list to a DataTable for binding to the DataGridView
$dataTable = New-Object System.Data.DataTable
# Define columns
$dataTable.Columns.Add("Name") | Out-Null
$dataTable.Columns.Add("Version") | Out-Null
$dataTable.Columns.Add("Publisher") | Out-Null
$dataTable.Columns.Add("InstallDate") | Out-Null
# Populate the DataTable
foreach ($program in $installedPrograms) {
$row = $dataTable.NewRow()
$row["Name"] = $program.Name
$row["Version"] = $program.Version
$row["Publisher"] = $program.Publisher
$row["InstallDate"] = $program.InstallDate
$dataTable.Rows.Add($row)
}
# Assign the DataTable as the DataSource for the DataGridView
$dataGridView.DataSource = $dataTable
# Add the DataGridView to the form
$form.Controls.Add($dataGridView)
# Display the form
$form.Add_Shown({ $form.Activate() })
[void]$form.ShowDialog()
Instructions:
Open Notepad or any text editor.
Copy and paste the script above into the editor.
Save the file with a .ps1 extension, e.g., ShowInstalledPrograms.ps1.
Open PowerShell as an administrator:
Click on the Start menu.
Type powershell.
Right-click on Windows PowerShell and select Run as administrator.
Navigate to the directory where you saved the script using the cd command.
By default, PowerShell might restrict script execution. To allow the script to run, set the execution policy:
Set-ExecutionPolicy RemoteSigned
If prompted, type Y to confirm.
Run the script:
.\ShowInstalledPrograms.ps1
Script Explanation:
Add-Type -AssemblyName System.Windows.Forms
Loads the Windows Forms library, which allows us to create GUI elements.
$form
Initializes the main window with specified size and title.
$dataGridView
A grid control used to display the data in a table format.
Get-InstalledPrograms Function
Queries the registry keys where installed programs are listed.
Handles both 32-bit and 64-bit applications by checking the Wow6432Node.
Collects program name, version, publisher, and installation date.
Data Binding
Converts the list of programs to a DataTable, which is then bound to the DataGridView for display.
Display
The form is displayed modally with $form.ShowDialog(), and the script waits until the window is closed.
Note:
The script reads from the registry to fetch installed programs. Some programs may not appear if they do not add entries to the standard uninstall registry keys.
The InstallDate may not always be available or may be in an unexpected format, depending on how the application stores it.
Running scripts requires appropriate execution policies. You can revert the policy to its default after running the script:
Set-ExecutionPolicy Restricted
Safety Considerations:
Always review scripts from the internet before running them to ensure they do not perform unintended actions.
Modifying the execution policy affects your system's security. Set it back to the original state if needed.
Let me know if you need further assistance or modifications to the script!