Skip to content

Commit 8506c83

Browse files
Merge pull request #291 from ZzBombardierzZ/patch-1
Update Win_ScreenConnectAIO.ps1 as .exe depreciated
2 parents 70643b3 + 37287b2 commit 8506c83

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

scripts/Win_ScreenConnectAIO.ps1

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<#
22
Requires global variables for serviceName "ScreenConnectService" and url "ScreenConnectInstaller"
3-
serviceName is the name of the ScreenConnect Service once it is installed EG: "ScreenConnect Client (1327465grctq84yrtocq)"
4-
url is the path the download the exe version of the ScreenConnect Access installer
3+
serviceName is the name of the ScreenConnect Service once it is installed EG: "ScreenConnect Client (1327465grctq84yrtocq)" or "ConnectWise Control Client (xxxxxx)"
4+
url is the path to download the MSI version of the ScreenConnect Access installer
55
Both variables values must start and end with "
66
Also accepts uninstall variable to remove the installed instance if required.
77
2022-10-12: Added -action start and -action stop variables
88
2024-3-19 silversword411 - Adding debug. Fixing uninstall when .exe not running.
9+
2024-06-18: Bomb - Updated for MSI-only support (.exe deprecated)
910
#>
1011

1112
param (
@@ -39,19 +40,24 @@ if (!$serviceName) {
3940
$ErrorCount += 1
4041
}
4142
if (!$url) {
42-
write-output "Variable not specified ScreenConnectInstaller, please create a global custom field under Client called ScreenConnectInstaller, Example Value: `"https://myinstance.screenconnect.com/Bin/ConnectWiseControl.ClientSetup.exe?h=stupidlylongurlhere`" `n"
43+
write-output "Variable not specified ScreenConnectInstaller, please create a global custom field under Client called ScreenConnectInstaller, Example Value: `"https://myinstance.screenconnect.com/Bin/ScreenConnect.ClientSetup.msi?h=stupidlylongurlhere`" `n"
4344
$ErrorCount += 1
4445
}
4546

46-
if (!$ErrorCount -eq 0) {
47+
if ($ErrorCount -ne 0) {
4748
exit 1
4849
}
4950

5051
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
52+
5153
if ($action -eq "uninstall") {
5254
$MyApp = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq "$serviceName" }
5355
Write-Debug "MyApp: $MyApp"
54-
$MyApp.Uninstall()
56+
if ($MyApp) {
57+
$MyApp.Uninstall()
58+
} else {
59+
Write-Output "No matching ScreenConnect product found to uninstall."
60+
}
5561
}
5662
elseif ($action -eq "stop") {
5763
If ((Get-Service $serviceName).Status -eq 'Running') {
@@ -66,9 +72,6 @@ elseif ($action -eq "stop") {
6672
Write-Error -Message "$ErrorMessage $FailedItem"
6773
exit 1
6874
}
69-
Finally {
70-
}
71-
7275
}
7376
}
7477
elseif ($action -eq "start") {
@@ -84,9 +87,6 @@ elseif ($action -eq "start") {
8487
Write-Error -Message "$ErrorMessage $FailedItem"
8588
exit 1
8689
}
87-
Finally {
88-
}
89-
9090
}
9191
}
9292
else {
@@ -104,12 +104,8 @@ else {
104104
Write-Error -Message "$ErrorMessage $FailedItem"
105105
exit 1
106106
}
107-
Finally {
108-
}
109-
110107
}
111108
Else {
112-
113109
Try {
114110
Write-Host "Starting $serviceName"
115111
Set-Service -Name $serviceName -Status running -StartupType automatic
@@ -121,28 +117,31 @@ else {
121117
Write-Error -Message "$ErrorMessage $FailedItem"
122118
exit 1
123119
}
124-
Finally {
125-
}
126-
127120
}
128121

129122
}
130123
Else {
131124

132125
$OutPath = $env:TMP
133-
$output = "screenconnect.exe"
126+
$output = "ScreenConnect.ClientSetup.msi"
134127

135128
Try {
136129
$start_time = Get-Date
137130
$wc = New-Object System.Net.WebClient
138131
$wc.DownloadFile("$url", "$OutPath\$output")
139132
Write-Debug "Time taken to download: $((Get-Date).Subtract($start_time).Seconds) second(s)"
140-
133+
141134
$start_time = Get-Date
142-
$wc = New-Object System.Net.WebClient
143-
Start-Process -FilePath $OutPath\$output -Wait
135+
# Install MSI silently
136+
$proc = Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$OutPath\$output`" /qn /norestart" -Wait -PassThru
144137
Write-Debug "Time taken to install: $((Get-Date).Subtract($start_time).Seconds) second(s)"
145-
exit 0
138+
if ($proc.ExitCode -eq 0) {
139+
Write-Host "ScreenConnect installed successfully."
140+
exit 0
141+
} else {
142+
Write-Error "ScreenConnect install failed with exit code $($proc.ExitCode)."
143+
exit $proc.ExitCode
144+
}
146145
}
147146
Catch {
148147
$ErrorMessage = $_.Exception.Message
@@ -151,7 +150,7 @@ else {
151150
exit 1
152151
}
153152
Finally {
154-
Remove-Item -Path $OutPath\$output
153+
Remove-Item -Path "$OutPath\$output" -Force -ErrorAction SilentlyContinue
155154
}
156155

157156
}

0 commit comments

Comments
 (0)