建议你这样试试看:
电脑一般无按键输入一定分钟后锁屏,所以每分钟模拟鼠标或键盘按下一个键就可以了。模拟用户 *** 作控制面板中,找到锁屏设置项,关闭。不同的Windows系统步骤氏让可能不一定,需要查找控制面板相关窗口的句柄,模拟鼠标点击来完整调整 *** 作。
由于Windows安全机制,据我所知好像没有函数能直接禁用电脑锁屏,只有锁屏的,没有阻止锁屏的。
API声明代码:
一般使用API的SendMessage和keybd_event和mouse_event
public static class 窗体API {[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam)
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam)
[DllImport("user32.dll", 裂蠢EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, string lParam)
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, StringBuilder lParam)
/// <summary>
/// 向窗口发送消息,执行后马上返回。
/// </summary>
/// <param name="hWnd"></param>
/// <param name="Msg"></param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
/// <returns></returns>
[DllImport("User32.dll", EntryPoint = "PostMessage")]
public static extern int PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam)
[DllImport("user32.dll", EntryPoint = "keybd_event", SetLastError = true)]
肆核陪 public static extern void keybd_event(Keys bVk, byte bScan, int dwFlags, int dwExtraInfo)
[DllImport("user32.dll", EntryPoint = "mouse_event", SetLastError = true)]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo)
[DllImport("User32.dll", EntryPoint = "SetCursor")]
public static extern int SetCursor(int hCursor)
[DllImport("User32.dll", EntryPoint = "SetCursorPos")]
public static extern int SetCursorPos(int x, int y)
[DllImport("user32.dll", EntryPoint = "GetCursorPos")]
public static extern int GetCursorPos(ref MOUSEPOINT lpPoint)
}
模拟按键
public class 模拟 {public static void 模拟按键(Keys 按键) {
窗体API.keybd_event(按键, 0, 0, 0)
窗体API.keybd_event(按键, 0, 2, 0)
}
public static void 模拟按键(Keys 组合键, Keys 按键) {
窗体API.keybd_event(组合键, 0, 0, 0)
窗体API.keybd_event(按键, 0, 0, 0)
窗体API.keybd_event(按键, 0, 2, 0)
窗体API.keybd_event(组合键, 0, 2, 0)
}
public static void 模拟按键(Keys 组合键1, Keys 组合键2, Keys 按键) {
窗体API.keybd_event(组合键1, 0, 0, 0)
窗体API.keybd_event(组合键2, 0, 0, 0)
窗体API.keybd_event(按键, 0, 0, 0)
窗体API.keybd_event(按键, 0, 2, 0)
窗体API.keybd_event(组合键2, 0, 2, 0)
窗体API.keybd_event(组合键1, 0, 2, 0)
}
public static void 按下(Keys 按键) {
窗体API.keybd_event(按键, 0, 0, 0)
}
public static void 抬起(Keys 按键) {
窗体API.keybd_event(按键, 0, 2, 0)
}
public static void 鼠标位置(int x, int y) {
窗体API.SetCursorPos(x, y)
}
/// <summary>相对当前位置的移动</summary>
public static void 鼠标移动(int x, int y) { 窗体API.mouse_event(0x1, x, y, 0, 0) }
public static void 按下左键(int x, int y) { 窗体API.mouse_event(0x2, x, y, 0, 0) }
public static void 抬起左键(int x, int y) { 窗体API.mouse_event(0x4, x, y, 0, 0) }
public static void 按下右键(int x, int y) { 窗体API.mouse_event(0x8, x, y, 0, 0) }
public static void 抬起右键(int x, int y) { 窗体API.mouse_event(0x10, x, y, 0, 0) }
public static void 按下中键(int x, int y) { 窗体API.mouse_event(0x20, x, y, 0, 0) }
public static void 抬起中键(int x, int y) { 窗体API.mouse_event(0x40, x, y, 0, 0) }
/// <summary>距离正数表示向上滚动,负值表示向下滚动。轮击定义为WHEEL_DELTA,即120。</summary>
public static void 鼠标滚动(int x, int y, int 距离) { 窗体API.mouse_event(0x800, x, y, 距离, 0) }
public static void 鼠标移至(int x, int y) { 窗体API.mouse_event(0x8000, x, y, 0, 0) }
}
调用的时候直接 模拟.模拟按键(Keys.Up) 就可以了
电脑锁屏时间非常短,写了个python小程序模拟鼠标移动,防止锁屏,结果没成功后简冲来加入模拟点击、模拟输入,最后才防止锁屏。1、登录主用AD,在开始菜单里点击“所有程序”,然后点击“管理工具”,然后点击“组策略管理”:
2、 在“组策略管理”里面,找到“Default Domain Policy”,右键选择“编辑”。
3、在“组策略管理编辑器”里按照下图找到“启用棚李屏幕保护程序”。
4、 双击“启用屏幕保护程链咐迟序”,设为“已禁用”。点击确定。
5、在主用AD的cmd命令行输入“gpupdate /force”,让客户端强制刷新组策略。
6、win7客户端最终的效果如下图。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)