Created
January 6, 2025 22:55
-
-
Save greenido/327cb6ba61d1035abe62f60048ddd692 to your computer and use it in GitHub Desktop.
Install VNC on windows11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires PowerShell to be run as Administrator | |
#Requires -RunAsAdministrator | |
# Function to check if TightVNC is installed | |
function Test-TightVNCInstalled { | |
$installed = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | | |
Where-Object { $_.DisplayName -like "*TightVNC*" } | |
return $null -ne $installed | |
} | |
# Function to enable Remote Desktop | |
function Enable-RemoteDesktop { | |
Write-Host "Enabling Remote Desktop..." -ForegroundColor Green | |
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value 0 | |
Enable-NetFirewallRule -DisplayGroup "Remote Desktop" | |
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name "UserAuthentication" -Value 1 | |
} | |
# Function to install TightVNC | |
function Install-TightVNC { | |
Write-Host "Downloading and installing TightVNC..." -ForegroundColor Green | |
# Download URL for TightVNC | |
$url = "https://www.tightvnc.com/download/2.8.63/tightvnc-2.8.63-gpl-setup-64bit.msi" | |
$outPath = "$env:TEMP\tightvnc-setup.msi" | |
try { | |
# Download the installer | |
Invoke-WebRequest -Uri $url -OutFile $outPath | |
# Install TightVNC silently | |
$arguments = "/i `"$outPath`" /quiet /norestart ADDLOCAL=Server,Viewer" | |
Start-Process -FilePath "msiexec.exe" -ArgumentList $arguments -Wait | |
# Clean up | |
Remove-Item -Path $outPath -Force | |
} | |
catch { | |
Write-Host "Error installing TightVNC: $_" -ForegroundColor Red | |
exit 1 | |
} | |
} | |
# Function to configure Windows Defender Firewall | |
function Set-FirewallRules { | |
Write-Host "Configuring firewall rules..." -ForegroundColor Green | |
# Add TightVNC Server to firewall exceptions | |
New-NetFirewallRule -DisplayName "TightVNC Server" ` | |
-Direction Inbound ` | |
-Action Allow ` | |
-Protocol TCP ` | |
-LocalPort 5900 ` | |
-Program "C:\Program Files\TightVNC\tvnserver.exe" ` | |
-ErrorAction SilentlyContinue | |
} | |
# Function to get IP address | |
function Get-LocalIPAddress { | |
$ip = Get-NetIPAddress | | |
Where-Object { | |
$_.AddressFamily -eq "IPv4" -and | |
$_.PrefixOrigin -eq "Dhcp" | |
} | | |
Select-Object -ExpandProperty IPAddress | |
return $ip | |
} | |
# Main script execution | |
Write-Host "Windows 11 Remote Access Setup Script" -ForegroundColor Cyan | |
Write-Host "=====================================" -ForegroundColor Cyan | |
# Enable Remote Desktop | |
Enable-RemoteDesktop | |
# Check and install TightVNC if not present | |
if (-not (Test-TightVNCInstalled)) { | |
Install-TightVNC | |
} else { | |
Write-Host "TightVNC is already installed." -ForegroundColor Yellow | |
} | |
# Configure firewall | |
Set-FirewallRules | |
# Get local IP address | |
$localIP = Get-LocalIPAddress | |
# Display connection information | |
Write-Host "`nSetup Complete!" -ForegroundColor Green | |
Write-Host "`nConnection Information:" -ForegroundColor Cyan | |
Write-Host "======================" -ForegroundColor Cyan | |
Write-Host "Your computer's IP address is: $localIP" | |
Write-Host "`nRemote Desktop:" -ForegroundColor Yellow | |
Write-Host "1. Open Remote Desktop Connection on the client computer" | |
Write-Host "2. Connect to: $localIP" | |
Write-Host "3. Use your Windows login credentials" | |
Write-Host "`nVNC Access:" -ForegroundColor Yellow | |
Write-Host "1. Use any VNC viewer on the client computer" | |
Write-Host "2. Connect to: $localIP:5900" | |
Write-Host "3. Use the password you set during TightVNC installation" | |
Write-Host "`nNote: For better security, consider using an SSH tunnel:" -ForegroundColor Magenta | |
Write-Host "ssh -L 5900:localhost:5900 username@$localIP" | |
Write-Host "Then connect VNC to: localhost:5900" | |
# Prompt to restart computer | |
$restart = Read-Host "`nDo you want to restart the computer now to apply all changes? (y/n)" | |
if ($restart -eq 'y') { | |
Restart-Computer -Force | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check for the latest: https://www.tightvnc.com/download/2.8.85/tightvnc-2.8.85-gpl-setup-64bit.msi