in reply to Re: How to execute win32 functions when the user session is locked.
in thread How to execute win32 functions when the user session is locked.

I tried to execute the bellow perl script and locked the user session...

$n=15; while($n>0) { print "$n,"; $n--; sleep(1); }
It worked as usual without any extra code..., There was no output when i locked the session, as i locked the session before the next second.
The output seen when I unlocked the session:
C:\Pradeep>perl test.pl 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1, C:\Pradeep>


When i run the script bellow which I use to connect to a server using win 32 functions like
SetForegroundWindow($_);
SendKeys("Password01");
etc...

it connected without any issues and the server login was successful.
But, when i lock my session in the middle of my execution and unlocked the session, the execution of script was completed, but the server login was not done.
use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow + SendKeys); system('"start %windir%\system32\mstsc.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; }


According to me I used the active windows for doing my functionality. So it is not working.
is there any other way i can successfully do the above functionality if the user session is locked in the middle of the execution process. or do i have to make changes in my code.??

Thanks...

Pradeep Krishna

Replies are listed 'Best First'.
Re^3: How to execute win32 functions when the user session is locked.
by Anonymous Monk on Feb 05, 2014 at 07:44 UTC
Re^3: How to execute win32 functions when the user session is locked.
by bulk88 (Priest) on Feb 06, 2014 at 05:16 UTC

      Here is hwndSendKeys , its close, but its broken (and i'm bored with it)

      sub hwndSendKeys { my ( $hwnd, $keys, $delay) = @_; $delay = 25 unless defined $delay; $delay /= 1000; my @k = Win32::GuiTest::parse_keys($keys); for ( my $i = 0; $i < @k; $i+=2) { if ( defined $k[$i]) { Win32::GuiTest::DbgShow("SendRawKey(@k[$i,$i+1])\n"); #~ Win32::GuiTest::SendRawKey( @k[$i,$i+1]); my( $key, $updown ) = @k[ $i, $i+1 ] ; my $wmupdown = WM_KEYDOWN(); $wmupdown = WM_KEYUP() if $updown == 2; Win32::GuiTest::PostMessage( $hwnd, $wmupdown, $key , 0 + ); select(undef,undef,undef,$delay); ## deprecated $i+=2; ### SUPER BROKEN otherwise DOUBLING bug } else { $k[$i+1]-> (); } } }