Guest User

Untitled

a guest
Jan 28th, 2025
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. try {
  2.     # Define the registry path and the value name
  3.     $regPath = "HKLM:\SYSTEM\ControlSet001\Services\ScreenConnect Client (XXXXXXXXXXXXXXXX)"
  4.     $valueName = "ImagePath"
  5.  
  6.     # Check if the registry key exists
  7.     if (Test-Path $regPath) {
  8.         # Try to read the current value of the registry key
  9.         $currentValue = (Get-ItemProperty -Path $regPath -Name $valueName).$valueName
  10.  
  11.         if ($currentValue) {
  12.             # Replace "p=443" with "p=8041"
  13.             $newValue = $currentValue -replace "p=443", "p=8041"
  14.  
  15.             # Update the registry with the new value
  16.             Set-ItemProperty -Path $regPath -Name $valueName -Value $newValue
  17.  
  18.             Write-Host "Updated 'ImagePath' value successfully!" -ForegroundColor Green
  19.             try {
  20.                 Restart-Service -Name "ScreenConnect Client (XXXXXXXXXXXXXXXX)" -Force
  21.                 Write-Host "ScreenConnect service restarted." -ForegroundColor Green
  22.             }
  23.             catch {
  24.                 Write-Host "ScreenConnect service could not be restarted." -ForegroundColor Red
  25.             }
  26.         } else {
  27.             Write-Warning "The registry entry '$valueName' does not contain a valid value."
  28.         }
  29.     } else {
  30.         Write-Error "The registry path '$regPath' does not exist."
  31.     }
  32. } catch {
  33.     # Catch any unexpected errors
  34.     Write-Error "An error occurred: $_"
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment