我试图执行波纹管脚本并锁定用户会话...
$n=15;
while($n>0)
{
print "$n,";
$n--;
sleep(1);
}
它照常工作没有任何额外的代码...,当我锁定会话时没有输出,因为我在下一秒钟之前锁定了会话。解锁会话时看到的输出:
C:Pradeep>perl test.pl
15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,
C:Pradeep>
运行脚本时,我用来使用Win32 :: Guitest函数将其用于连接到服务器SetForegroundWindow($ _);sendkeys(" password01");ETC...它在没有任何问题的情况下连接,服务器登录成功。但是,当我将会话锁定在执行中间并解锁会话时,执行脚本已完成,但是服务器登录未完成。
use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow SendKeys);
system('"start %windir%system32mstsc.exe"');
$Win32::GuiTest::debug = 0;
$max_Sleep_time=3;
$Cur_Sleep_time=0;
do
{
sleep(1);
@windows = FindWindowLike(0, "Remote Desktop Connection");
$number_of_windows_opend = scalar(@windows);
$Cur_Sleep_time++;
}while ($number_of_windows_opend==0&&$Cur_Sleep_time!=$max_Sleep_time);
for (@windows) {
SetForegroundWindow($_);
SendKeys("server_name");
SendKeys("{ENTER}");
sleep(10);
@windows_seq = FindWindowLike(0, "Windows Security");
for (@windows_seq) {
SetForegroundWindow($_);
SendKeys("Password01");
SendKeys("{ENTER}");
}
@windows={};
exit;
}
根据我的说法,我使用了活动窗口来执行我的功能。因此它不起作用。如果用户会话锁定在执行过程的中间,我还有其他任何方法可以成功地执行上述功能。还是我必须更改我的代码?
而不是使用发送键使用wmsetText();功能。它将窗口/控制HWND和文本作为输入,并将文本设置为指定的对象。
注意:使用wmsetText();您只需设置文本,就不能发送键,例如{enter},{f1}等...
您已经多次被告知答案:
- http://perlmonks.org/?node_id=1073507
- http://perlmonks.org/?node_id=1073302
- http://perlmonks.org/?node_id=1073530
Win32 :: Guitest的文档中解释了这一点。出于明显的安全原因,当屏幕锁定时,您无法将钥匙发送到应用程序,您无法将键发送给不活动的适应。