
Windows 11 IoT Enterprise LTSC 2024 Deployment Guide
PowerShell script for TightVNC
# Removal Functions
function Stop-TightVNCService {
$serviceName = "TightVNC Server"
$tvnServerPath = "C:\Program Files\TightVNC\tvnserver.exe"
if (Test-Path $tvnServerPath) {
$service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
if ($service -and $service.Status -eq 'Running') {
Stop-Service -Name $serviceName -Force
Start-Sleep -Seconds 5
}
}
}
function Unregister-TightVNCService {
$serviceName = "TightVNC Server"
$tvnServerPath = "C:\Program Files\TightVNC\tvnserver.exe"
if (Test-Path $tvnServerPath) {
$service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
if ($service) {
$service_by_name = Get-WmiObject -Class Win32_Service -Filter "Name='tvnserver'"
$ret = $service_by_name.stopservice()
$ret = $service_by_name.delete()
Start-Sleep -Seconds 5
}
}
}
function Remove-TightVNCStartMenu {
$startMenuPath = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\TightVNC"
if (Test-Path $startMenuPath) {
Remove-Item -Recurse -Force $startMenuPath
Start-Sleep -Seconds 3
}
}
function Remove-TightVNCFolder {
$installPath = "C:\Program Files\TightVNC"
if (Test-Path $installPath) {
Remove-Item -Recurse -Force $installPath
Start-Sleep -Seconds 5
}
}
function Remove-TightVNCFromStartup {
$startupKey = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run"
$startupApp = "tvncontrol"
if (Test-Path $startupKey) {
$currentApps = Get-ItemProperty -Path $startupKey
if ($currentApps.PSObject.Properties.Name -contains $startupApp) {
Remove-ItemProperty -Path $startupKey -Name $startupApp
Start-Sleep -Seconds 3
}
}
}
# Define the registry path
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
# Search for TightVNC in the uninstall registry keys
$tightVNCKey = Get-ChildItem $regPath | ForEach-Object {
Get-ItemProperty $_.PSPath
} | Where-Object { $_.DisplayName -like "*TightVNC*" }
if ($tightVNCKey) {
$uninstallString = $tightVNCKey.UninstallString
if ($uninstallString) {
# Replace /i with /x (case-insensitive)
if ($uninstallString -match "Msiexec\.exe") {
$uninstallString = $uninstallString -replace "(?i)/i", "/x"
}
# Add silent switch if not present
if ($uninstallString -notmatch "/quiet|/silent") {
$uninstallString += " /qn"
}
# Execute uninstall command
Start-Process -FilePath "cmd.exe" -ArgumentList "/c $uninstallString" -Wait
Start-Sleep -Seconds 5
}
} else {
# Main Execution
Stop-TightVNCService
Unregister-TightVNCService
Remove-TightVNCStartMenu
Remove-TightVNCFromStartup
Remove-TightVNCFolder
}
# Final Validation + Auto-Fix
$validationPassed = $true
# Validate Service
$service = Get-Service -Name "TightVNC Server" -ErrorAction SilentlyContinue
if ($service) {
try {
Stop-Service -Name "TightVNC Server" -Force -ErrorAction SilentlyContinue
$service_by_name = Get-WmiObject -Class Win32_Service -Filter "Name='tvnserver'"
$service_by_name.stopservice()
$service_by_name.delete() | Out-Null
} catch {
# This catch block is empty, meaning no explicit actions are taken when an error is caught.
# The error message will not be displayed, and the script will continue after the catch block.
}
$validationPassed = $false
}
# Validate Start Menu
$startMenuPath = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\TightVNC"
if (Test-Path $startMenuPath) {
Remove-Item -Recurse -Force $startMenuPath -ErrorAction SilentlyContinue
$validationPassed = $false
}
# Validate Startup Entry
$startupKey = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run"
$currentApps = Get-ItemProperty -Path $startupKey
if ($currentApps.PSObject.Properties.Name -contains "tvncontrol") {
Remove-ItemProperty -Path $startupKey -Name "tvncontrol" -ErrorAction SilentlyContinue
$currentApps = Get-ItemProperty -Path $startupKey
$validationPassed = $false
}
# Validate Installation Folder
$installPath = "C:\Program Files\TightVNC"
if (Test-Path $installPath) {
Remove-Item -Recurse -Force $installPath -ErrorAction SilentlyContinue
$validationPassed = $false
}
Please provide ratings (1-5 stars).
Please provide ratings (1-5 stars).
Please provide ratings (1-5 stars).
Please select whether the article was helpful or not.
Comments cannot contain these special characters: <>()\