-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSilent_Installer.ps1
More file actions
165 lines (139 loc) · 4.5 KB
/
Silent_Installer.ps1
File metadata and controls
165 lines (139 loc) · 4.5 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
param(
[Parameter(Mandatory = $true)]
[ValidateSet("thunderbird","firefox","chrome","vlc","adobe","java")]
[string]$App,
# Ordner mit Installern (empfohlen von Python übergeben)
[Parameter(Mandatory = $false)]
[string]$FilesDir
)
$ErrorActionPreference = "Stop"
# ---------------------------
# FilesDir ermitteln (robust)
# ---------------------------
if ([string]::IsNullOrWhiteSpace($FilesDir)) {
# Default: aktuelles Arbeitsverzeichnis + \Files (Python setzt cwd=EXE_DIR)
$FilesDir = Join-Path (Get-Location) "Files"
}
if (-not (Test-Path -Path $FilesDir)) {
Write-Output "STATUS:ERROR FilesDir not found: $FilesDir"
exit 10
}
# ---------------------------
# Helper: Installer finden
# ---------------------------
function Get-InstallerPath {
param(
[Parameter(Mandatory = $true)]
[string]$Pattern
)
$installer = Get-ChildItem -Path $FilesDir -Filter $Pattern -File -ErrorAction SilentlyContinue |
Select-Object -First 1
if (-not $installer) {
Write-Output "STATUS:MISSING Installer not found: $Pattern (in $FilesDir)"
exit 11
}
return $installer.FullName
}
# ---------------------------
# Helper: Uninstall-Checks
# ---------------------------
function Test-UninstallDisplayNameMatch {
param(
[Parameter(Mandatory=$true)]
[string]$Regex
)
# 64-bit + 32-bit Uninstall
$paths = @(
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
foreach ($p in $paths) {
$hit = Get-ItemProperty $p -ErrorAction SilentlyContinue |
Where-Object { $_.DisplayName -match $Regex } |
Select-Object -First 1
if ($hit) { return $true }
}
return $false
}
# ---------------------------
# Installer Funktionen
# ---------------------------
function Install-Thunderbird {
if (Test-UninstallDisplayNameMatch "Thunderbird") {
Write-Output "STATUS:ALREADY Thunderbird"
return
}
$exe = Get-InstallerPath "thunderbird*.exe"
Start-Process -FilePath $exe -ArgumentList "/S /quiet" -Wait
Write-Output "STATUS:INSTALLED Thunderbird"
}
function Install-Firefox {
if (Test-UninstallDisplayNameMatch "Firefox") {
Write-Output "STATUS:ALREADY Firefox"
return
}
# Tipp: Viele Firefox-Installer heißen "Firefox Setup*.exe"
$exe = Get-InstallerPath "*Firefox*.exe"
Start-Process -FilePath $exe -ArgumentList "-ms -ma" -Wait
Write-Output "STATUS:INSTALLED Firefox"
}
function Install-Chrome {
$chromePath = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe' -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty '(Default)' -ErrorAction SilentlyContinue
if ($chromePath) {
Write-Output "STATUS:ALREADY Chrome"
return
}
$exe = Get-InstallerPath "chrome*.exe"
Start-Process -FilePath $exe -ArgumentList "/silent /install" -Wait
Write-Output "STATUS:INSTALLED Chrome"
}
function Install-VLC {
if (Test-UninstallDisplayNameMatch "VLC") {
Write-Output "STATUS:ALREADY VLC"
return
}
$exe = Get-InstallerPath "vlc*.exe"
Start-Process -FilePath $exe -ArgumentList "/S /L=1031" -Wait
Write-Output "STATUS:INSTALLED VLC"
}
function Install-Adobe {
if (Test-UninstallDisplayNameMatch "Adobe Acrobat Reader|Adobe Reader") {
Write-Output "STATUS:ALREADY AdobeReader"
return
}
$exe = Get-InstallerPath "AcroRdrDC*.exe"
Start-Process -FilePath $exe -ArgumentList "/sAll /rs /msi EULA_ACCEPT=YES" -Wait
Write-Output "STATUS:INSTALLED AdobeReader"
}
function Install-Java {
if (Test-UninstallDisplayNameMatch "Java") {
Write-Output "STATUS:ALREADY Java"
return
}
$exe = Get-InstallerPath "jre*.exe"
Start-Process -FilePath $exe -ArgumentList "/s" -Wait
Write-Output "STATUS:INSTALLED Java"
}
# ---------------------------
# Main
# ---------------------------
try {
switch ($App) {
"thunderbird" { Install-Thunderbird }
"firefox" { Install-Firefox }
"chrome" { Install-Chrome }
"vlc" { Install-VLC }
"adobe" { Install-Adobe }
"java" { Install-Java }
default {
Write-Output "STATUS:ERROR Unknown App: $App"
exit 12
}
}
exit 0
}
catch {
Write-Output ("STATUS:ERROR " + $_.Exception.Message)
exit 13
}