求助:通过脚本模拟用户输入保持Citrix Windows 10 VDI持续运行
防止Citrix VDI闲置断开的脚本方案
PowerShell脚本(模拟鼠标微动)
该脚本每隔90分钟将鼠标移动1像素后移回原位,避免系统判定为闲置状态。
# 引入Windows API控制鼠标 Add-Type @" using System; using System.Runtime.InteropServices; public class MouseMove { [DllImport("user32.dll")] public static extern bool SetCursorPos(int X, int Y); } "@ # 循环执行鼠标微动 while ($true) { # 获取当前鼠标位置 $pos = [System.Windows.Forms.Cursor]::Position # 向右移动1像素 [MouseMove]::SetCursorPos($pos.X + 1, $pos.Y) Start-Sleep -Milliseconds 100 # 移回原位置 [MouseMove]::SetCursorPos($pos.X, $pos.Y) # 等待90分钟 Start-Sleep -Seconds 5400 }
使用说明
- 将代码保存为
PreventIdle.ps1 - 右键以管理员身份运行PowerShell,执行命令:
.\PreventIdle.ps1 - 如需后台自动运行,可创建Windows任务计划,设置为登录后启动,重复间隔设为90分钟
VBScript脚本(模拟按键输入)
该脚本每隔1小时发送一次Scroll Lock按键信号,触发系统判定为有用户操作。
Set WshShell = CreateObject("WScript.Shell") Do # 发送Scroll Lock按键(按下再松开) WshShell.SendKeys "{SCROLLLOCK}" WScript.Sleep 100 WshShell.SendKeys "{SCROLLLOCK}" # 等待1小时 WScript.Sleep 3600000 Loop
使用说明
- 将代码保存为
PreventIdle.vbs - 双击即可运行,脚本会在后台持续执行
- 如需关闭,打开任务管理器结束
wscript.exe进程即可
内容的提问来源于stack exchange,提问作者CodeBot
相关产品推荐
相关产品推荐

