Skip to content

Commit

Permalink
Merge pull request #224 from silversword411/main
Browse files Browse the repository at this point in the history
Fixing Screenconnect AIO
  • Loading branch information
silversword411 committed Mar 28, 2024
2 parents 4fad311 + 401197e commit 0c0fc0d
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 85 deletions.
8 changes: 4 additions & 4 deletions community_scripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -1064,11 +1064,11 @@
"-serviceName {{client.ScreenConnectService}}",
"-url {{client.ScreenConnectInstaller}}",
"-clientname {{client.name}}",
"-sitename {{site.name}}",
"-action {(install) | uninstall | start | stop}"
"-sitename {{site.name}}"
],
"default_timeout": "90",
"default_timeout": "120",
"shell": "powershell",
"syntax": "-serviceName <string>\n-url <string>\n-clientname <string>\n-sitename <string>\n-action {(install) | uninstall | start | stop}",
"supported_platforms": [
"windows"
],
Expand Down Expand Up @@ -1706,4 +1706,4 @@
],
"category": "TRMM (All):3rd Party Software"
}
]
]
167 changes: 86 additions & 81 deletions scripts/Win_ScreenConnectAIO.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,33 @@ url is the path the download the exe version of the ScreenConnect Access install
Both variables values must start and end with "
Also accepts uninstall variable to remove the installed instance if required.
2022-10-12: Added -action start and -action stop variables
2024-3-19 silversword411 - Adding debug. Fixing uninstall when .exe not running.
#>

param (
[string] $serviceName,
[string] $url,
[string] $clientname,
[string] $sitename,
[string] $action
[string] $serviceName,
[string] $url,
[string] $clientname,
[string] $sitename,
[string] $action,
[switch] $debug
)

$clientname = $clientname.Replace(" ","%20")
$sitename = $sitename.Replace(" ","%20")
$url = $url.Replace("&t=&c=&c=&c=&c=&c=&c=&c=&c=","&t=&c=$clientname&c=$sitename&c=&c=&c=&c=&c=&c=")
# For setting debug output level. -debug switch will set $debug to true
if ($debug) {
$DebugPreference = "Continue"
$ErrorActionPreference = 'Continue'
Write-Debug "Debug mode enabled"
}
else {
$DebugPreference = "SilentlyContinue"
$ErrorActionPreference = 'silentlycontinue'
Write-Output "Regular mode enabled"
}

$clientname = $clientname.Replace(" ", "%20")
$sitename = $sitename.Replace(" ", "%20")
$url = $url.Replace("&t=&c=&c=&c=&c=&c=&c=&c=&c=", "&t=&c=$clientname&c=$sitename&c=&c=&c=&c=&c=&c=")
$ErrorCount = 0

if (!$serviceName) {
Expand All @@ -30,122 +44,113 @@ if (!$url) {
}

if (!$ErrorCount -eq 0) {
exit 1
exit 1
}

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if ($action -eq "uninstall") {
$MyApp = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "$serviceName"}
$MyApp.Uninstall()
} elseif ($action -eq "stop") {
$MyApp = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq "$serviceName" }
Write-Debug "MyApp: $MyApp"
$MyApp.Uninstall()
}
elseif ($action -eq "stop") {
If ((Get-Service $serviceName).Status -eq 'Running') {
Try
{
Try {
Write-Output "Stopping $serviceName"
Set-Service -Name $serviceName -Status stopped -StartupType disabled
exit 0
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Error -Message "$ErrorMessage $FailedItem"
exit 1
}
Finally
{
}

}
} elseif ($action -eq "start") {
If ((Get-Service $serviceName).Status -ne 'Running') {
Try
{
Catch {
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Error -Message "$ErrorMessage $FailedItem"
exit 1
}
Finally {
}

}
}
elseif ($action -eq "start") {
If ((Get-Service $serviceName).Status -ne 'Running') {
Try {
Write-Host "Starting $serviceName"
Set-Service -Name $serviceName -Status running -StartupType automatic
exit 0
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Error -Message "$ErrorMessage $FailedItem"
exit 1
}
Finally
{
}

}
} else {
Catch {
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Error -Message "$ErrorMessage $FailedItem"
exit 1
}
Finally {
}

}
}
else {
If (Get-Service $serviceName -ErrorAction SilentlyContinue) {

If ((Get-Service $serviceName).Status -eq 'Running') {
Try
{
Write-Output "Stopping $serviceName"
Set-Service -Name $serviceName -Status stopped -StartupType disabled
exit 0
Try {
Write-Output "Stopping $serviceName"
Set-Service -Name $serviceName -Status stopped -StartupType disabled
exit 0
}
Catch
{
Catch {
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Error -Message "$ErrorMessage $FailedItem"
exit 1
}
Finally
{
}
}
Finally {
}

} Else {
}
Else {

Try
{
Write-Host "Starting $serviceName"
Set-Service -Name $serviceName -Status running -StartupType automatic
exit 0
Try {
Write-Host "Starting $serviceName"
Set-Service -Name $serviceName -Status running -StartupType automatic
exit 0
}
Catch
{
Catch {
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Error -Message "$ErrorMessage $FailedItem"
exit 1
}
Finally
{
}
}
Finally {
}

}

} Else {
}
Else {

$OutPath = $env:TMP
$output = "screenconnect.exe"

Try
{
$start_time = Get-Date
$wc = New-Object System.Net.WebClient
$wc.DownloadFile("$url", "$OutPath\$output")
Write-Output "Time taken to download: $((Get-Date).Subtract($start_time).Seconds) second(s)"
Try {
$start_time = Get-Date
$wc = New-Object System.Net.WebClient
$wc.DownloadFile("$url", "$OutPath\$output")
Write-Debug "Time taken to download: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$start_time = Get-Date
$wc = New-Object System.Net.WebClient
Start-Process -FilePath $OutPath\$output -Wait
Write-Output "Time taken to install: $((Get-Date).Subtract($start_time).Seconds) second(s)"
$start_time = Get-Date
$wc = New-Object System.Net.WebClient
Start-Process -FilePath $OutPath\$output -Wait
Write-Debug "Time taken to install: $((Get-Date).Subtract($start_time).Seconds) second(s)"
exit 0
}
Catch
{
Catch {
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Error -Message "$ErrorMessage $FailedItem"
exit 1
}
Finally
{
Finally {
Remove-Item -Path $OutPath\$output
}

Expand Down

0 comments on commit 0c0fc0d

Please sign in to comment.