marcpascual has asked for the wisdom of the Perl Monks concerning the following question:

hi. Im quite new with perl, and is there a way to lock the desktop in winxp via perl scripts?

Replies are listed 'Best First'.
Re: lock WinXP Desktop with perl
by ikegami (Patriarch) on Feb 23, 2006 at 07:09 UTC

    Bad news: I can't find any existing module to do this.

    Good news: Win32::API can be used to access all system calls and any DLL using only Perl and no compiler. The system call in question appears to be LockWorkStation.

    Update: It might be as simple as the following (untested) code:

    use Win32::API (); Win32::API->Import("user32", "BOOL LockWorkStation()"); LockWorkStation();

    Update: Here's a tested version with error checking:

    use Win32::API (); Win32::API->Import("user32", "BOOL LockWorkStation()") or die("Unable to import LockWorkStation: $^E\n"); LockWorkStation() or die("Unable to lock workstation: $^E\n");

    If Import returns false and $^E is numerically equal to 127 ("The specified procedure could not be found"), then it's probably because the function is not required on that particular OS.

Re: lock WinXP Desktop with perl
by Ultra (Hermit) on Feb 23, 2006 at 07:39 UTC

    Maybe the following line could prove to be useful too.

    %windir%\system32\rundll32.exe user32.dll, LockWorkStation

    Dodge This!