pradeep,krishna has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on 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 davido (Cardinal) on Feb 05, 2014 at 05:38 UTC

      While posting the last question I did not try any normal script like

      $n=15; while($n>0) { print "$n,"; $n--; sleep(1); }
      I tried to execute the above perl script and locked the user session...
      I had thought that I can not execute any perl script if the user session is locked in the middle of execution.

      But, 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>


      If a normal script is running fine in those conditions then there might be a way where i can change the code or code pattern or add some code to the existing code which uses the win 32 functions and can be executed successfully in the condition I mentioned above.

      Thanks...

      Pradeep Krishna :)

Re: How to execute win32 functions when the user session is locked.
by kcott (Archbishop) on Feb 05, 2014 at 04:47 UTC

    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

      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

      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 :)