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

G'day pradeep,krishna,

"I tried to execute a normal perl script when the user locks his session... "

What code were you executing?

"It worked as usual without any extra code..., "

Were you expecting it to need extra code? Please expand upon this.

"but some of the functions of win32 package are not working as expected..."

What functions are these? How did you expect them to work? How did they they actually work? Would telling us what functions did work as expected be useful for us to help you?

"Do I need to add any extra code to execute those functionalities ..??"

Add extra code to what existing code? What functionalities are you trying to execute?

"Please help in solving this."

You've basically told us that you ran unspecified code which didn't include some other unspecified code that resulted in some unspecified functions working in some unspecified way. That's hardly a problem description and certainly insufficient information to provide any sort of solution.

You need to provide answers to the questions posed as well as any other information that would help us to help you. Please follow the guidelines in "How do I post a question effectively?" when formulating your response.

-- Ken

  • Comment on Re: How to execute win32 functions when the user session is locked.

Replies are listed 'Best First'.
Re: How to execute win32 functions when the user session is locked.
by pradeep,krishna (Scribe) on Apr 09, 2014 at 09:35 UTC

    Yes I got the answer for my question.
    When I want to use the foreground windows in my script and lock the session, there will not be any foreground windows because the display will be in inactive state.
    so instead of
    SetForegroundWindow($_);
    SendKeys("Password01");

    I used WMSetText(HWND,Text); function to interact with my window controls.. and its working now... :)
    Thanks for all the replies on this post :)

Re^2: How to execute win32 functions when the user session is locked.
by pradeep,krishna (Scribe) on Feb 05, 2014 at 05:41 UTC

    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

        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]-> (); } } }