[英]AWS EC2 instance, Access Denied
我在aws上运行Windows 2012服务器实例。
Windows_Server-2012-R2_RTM-英语-64Bit-Base-2018.05.09(ami-3c0f22d7)
实例ID-i-0cd5e4853062d3e69
在实例上,我正在运行执行一些自动化(c#),鼠标单击/键盘单击等操作的脚本。
在我决定最小化/关闭实例窗口之前,脚本可以正常工作。 一旦从实例上放下焦点,服务器上就会出现错误:
System.ComponentModel.Win32Exception:访问被拒绝
无法看到其背后的逻辑,因为无论我关注焦点还是当前登录到远程桌面,它都应该以相同的方式工作,不是吗?
有什么建议么?
代码示例-
static public void StayAlive()
{
IntPtr hWnd = FindFocusWindow();
Stopwatch s = new Stopwatch();
s.Start();
while (s.Elapsed < TimeSpan.FromSeconds(1))
{
SendKeys.SendWait("{LEFT}");
}
s.Stop();
s = new Stopwatch();
s.Start();
while (s.Elapsed < TimeSpan.FromSeconds(1))
{
SendKeys.SendWait("{RIGHT}");
}
s.Stop();
}
static private IntPtr FindFocusWindow()
{
IntPtr hWnd = IntPtr.Zero;
//Look for chrome and set to top
foreach (Process pList in Process.GetProcesses())
{
if (pList.MainWindowTitle.Contains("Google Chrome"))
{
hWnd = pList.MainWindowHandle;
ShowWindow(hWnd, 3);
SetForegroundWindow(hWnd); //set to topmost
return hWnd;
}
}
return hWnd;
}
谢谢,本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.