0

I have this code:

<?php
system('shutdown -s');
?>

It works just fine, shuts down my localhost and everything. But this doesn't lock the computer:

<?php    
system('Rundll32.exe System32\User32.dll,LockWorkStation');
?>

Why doesn't it work?

14
  • Sorry, the code wasn't formatted correctly the first time for some reason. Commented Jul 4, 2012 at 0:34
  • Did you try your second command in a simple DOS prompt? (outside of PHP) Commented Jul 4, 2012 at 0:44
  • @Jocelyn that is a valid a command on windows. Commented Jul 4, 2012 at 0:45
  • 1
    @David that wasn't my question. Commented Jul 4, 2012 at 0:46
  • 2
    Does it work better using the full path to Rundll32.exe? On my computer it is "C:\WINNT\system32\Rundll32.exe", you'll have to check what is the correct path on your computer. Also maybe with forward slashes instead of backslashes... Commented Jul 4, 2012 at 1:06

1 Answer 1

1

The web server isn't running in the user session, and so has no ability to lock it.

Sign up to request clarification or add additional context in comments.

3 Comments

Because the system can be shut down by anything with appropriate privileges; doing so doesn't require a user session.
Okay, do you have any other suggestions on how I could lock the computer?
Run a user daemon that performs the lock instead, and communicate with it using mailslots or the like.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.