using System;
using System.Drawing;
using VncSharp;
public class SecureVncServer : VncServer
{
// 設置 VNC 連接密碼(需為 8 字符)
private readonly string vncPassword = "12345678";
public SecureVncServer()
{
// 設置密碼(自動轉換為 VNC 認證格式)
Password = vncPassword.ToCharArray();
}
protected override void ProvidePassword(byte[] challenge)
{
// 密碼驗證邏輯(VncSharp 自動處理加密驗證)
}
// 屏幕捕獲實現
public override Bitmap CaptureScreen()
{
Rectangle bounds = Screen.PrimaryScreen.Bounds;
Bitmap bmp = new Bitmap(bounds.Width, bounds.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
return bmp;
}
}
class Program
{
static void Main()
{
var vncServer = new SecureVncServer();
// 啟動服務(端口 5900)
try
{
vncServer.Start(5900);
Console.WriteLine($"VNC Server 已啟動,密碼: {vncServer.Password}");
Console.WriteLine("按 Enter 鍵停止服務...");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine($"啟動失敗: {ex.Message}");
}
finally
{
vncServer.Stop();
}
}
}