-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetInstallerType.ps1
More file actions
92 lines (83 loc) · 3.15 KB
/
GetInstallerType.ps1
File metadata and controls
92 lines (83 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
function Get-InstallerType {
param (
[string]$Path
)
if (!(Test-Path $Path -PathType Leaf)) {
Write-Error "File not found: $Path"
return
}
$ExecutablePath = (Get-Item $Path).FullName
$installerTypes = @{
"Inno Setup" = "Inno Setup";
"Nullsoft" = "NSIS (Nullsoft Scriptable Install System)";
"InstallShield" = "InstallShield";
"Wise" = "Wise Installer";
"WiX Toolset" = "WiX (Windows Installer XML)";
"Advanced Installer" = "Advanced Installer";
}
$quietArgumentStrings = @{
"Inno Setup" = "/VERYSILENT /NORESTART"
"Nullsoft" = "/allusers /S"
"InstallShield" = "-s -SMS"
"Wise" = "/S"
"WiX Toolset" = "/quiet"
}
$detectedType = "Unknown"
# Read file details
try {
$fileInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ExecutablePath)
$description = $fileInfo.FileDescription
$productName = $fileInfo.ProductName
$companyName = $fileInfo.CompanyName
$version = $fileInfo.FileVersion
$metaData = "$description $productName $companyName"
foreach ($key in $installerTypes.Keys) {
if ($metaData -match [regex]::Escape($key)) {
$detectedType = $installerTypes[$key]
break
}
}
} catch {
Write-Error "Failed to read file properties."
}
# If still unknown, scan for installer-specific signatures in the file content
if ($detectedType -eq "Unknown") {
try {
$fileContent = Get-Content $ExecutablePath -Raw -ErrorAction Stop
foreach ($key in $installerTypes.Keys) {
if ($fileContent -match [regex]::Escape($key)) {
$detectedType = $installerTypes[$key]
break
}
}
} catch {
Write-Error "Failed to read binary data."
}
}
# If the program is already installed, check the registry
if ($detectedType -eq "Unknown") {
$regPaths = @(
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
foreach ($path in $regPaths) {
$uninstallEntries = Get-ItemProperty -Path $path -ErrorAction SilentlyContinue | Where-Object { $_.UninstallString -like "*$ExecutablePath*" }
if ($uninstallEntries) {
$uninstallString = $uninstallEntries.UninstallString
if ($uninstallString -match "uninstall.exe /S") { $detectedType = "NSIS (Nullsoft)" }
elseif ($uninstallString -match "setup.exe /silent") { $detectedType = "InstallShield" }
elseif ($uninstallString -match "msiexec.exe") { $detectedType = "MSI (Windows Installer)" }
break
}
}
}
# Output result
[PSCustomObject]@{
FilePath = $ExecutablePath
InstallerType = $detectedType
Version = $version
ProductName = $productName
}
}
# Example usage:
# Get-InstallerType "C:\Path\To\Installer.exe"