-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver_installer.ps1
More file actions
130 lines (108 loc) · 3.64 KB
/
driver_installer.ps1
File metadata and controls
130 lines (108 loc) · 3.64 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
Param(
[string]$Mode = "Install"
)
[CmdletBinding()]
$ErrorActionPreference = "Continue"
if ($Mode -eq "Install") {
Write-Output "STATUS:INIT"
Write-Output "PROGRESS:5"
}
try {
$updateSession = New-Object -ComObject Microsoft.Update.Session
$updateSession.ClientApplicationID = "SL-Driver"
$updateSearcher = $updateSession.CreateUpdateSearcher()
} catch {
Write-Output "ERROR:COM_FAILED"
exit 1
}
if ($Mode -eq "Install") {
Write-Output "STATUS:SEARCHING"
Write-Output "PROGRESS:10"
} elseif ($Mode -eq "Search") {
Write-Output "STATUS:SEARCHING"
}
try {
# 드라이버만 검색
$searchResult = $updateSearcher.Search("IsInstalled=0 and Type='Driver' and IsHidden=0")
} catch {
Write-Output "ERROR:SEARCH_FAILED:$($_.Exception.Message)"
exit 1
}
if ($searchResult.Updates.Count -eq 0) {
if ($Mode -eq "Search") {
Write-Output "LOG:NO_UPDATES"
exit 0
}
Write-Output "STATUS:UP_TO_DATE"
Write-Output "PROGRESS:100"
exit 0
}
$totalUpdates = $searchResult.Updates.Count
if ($Mode -eq "Search") {
Write-Output "LOG:FOUND:$totalUpdates"
for ($i = 0; $i -lt $totalUpdates; $i++) {
$update = $searchResult.Updates.Item($i)
Write-Output "LOG:ITEM:$($update.Title)"
}
exit 0
}
Write-Output "STATUS:FOUND:$totalUpdates"
Write-Output "PROGRESS:20"
$progressRemaining = 80
$stepProgress = $progressRemaining / ($totalUpdates * 2)
$currentProgress = 20
$rebootRequired = $false
for ($i = 0; $i -lt $totalUpdates; $i++) {
$update = $searchResult.Updates.Item($i)
$singleUpdateColl = New-Object -ComObject Microsoft.Update.UpdateColl
$singleUpdateColl.Add($update) | Out-Null
$updateTitle = $update.Title
Write-Output "STATUS:DOWNLOADING:$($i+1):${totalUpdates}:${updateTitle}"
$downloader = $updateSession.CreateUpdateDownloader()
$downloader.Updates = $singleUpdateColl
try {
$dlResult = $downloader.Download()
$currentProgress += $stepProgress
Write-Output "PROGRESS:$([math]::Round($currentProgress))"
if ($dlResult.ResultCode -ne 2) {
Write-Output "WARNING:DOWNLOAD_FAILED:${updateTitle}:$($dlResult.ResultCode)"
$currentProgress += $stepProgress
Write-Output "PROGRESS:$([math]::Round($currentProgress))"
continue
}
} catch {
Write-Output "WARNING:DOWNLOAD_EXCEPTION:${updateTitle}:$($_.Exception.Message)"
$currentProgress += $stepProgress
Write-Output "PROGRESS:$([math]::Round($currentProgress))"
continue
}
Write-Output "STATUS:INSTALLING:$($i+1):${totalUpdates}:${updateTitle}"
try {
if (-not $update.EulaAccepted) {
$update.AcceptEula()
}
$installer = $updateSession.CreateUpdateInstaller()
$installer.Updates = $singleUpdateColl
$instResult = $installer.Install()
$currentProgress += $stepProgress
Write-Output "PROGRESS:$([math]::Round($currentProgress))"
if ($instResult.ResultCode -eq 2 -or $instResult.ResultCode -eq 3) {
if ($instResult.RebootRequired) {
$rebootRequired = $true
}
} else {
Write-Output "WARNING:INSTALL_FAILED:${updateTitle}:$($instResult.ResultCode)"
}
} catch {
Write-Output "WARNING:INSTALL_EXCEPTION:${updateTitle}:$($_.Exception.Message)"
$currentProgress += $stepProgress
Write-Output "PROGRESS:$([math]::Round($currentProgress))"
}
}
Write-Output "PROGRESS:100"
if ($rebootRequired) {
Write-Output "STATUS:DONE_REBOOT"
} else {
Write-Output "STATUS:DONE"
}
exit 0