Mike Silverman documenting innovation at work

13Nov/1015

Put Your PC Monitor to Sleep With an iPhone

iPhoneMonitor

When I go to sleep at night I like it dark. I also keep my computer on 24/7. In the past when going to sleep I would hit the power switch on my monitor. Or more often than not I would leave it on. Now when I'm in bed I click an icon on my iPhone and the monitor turns off. You can have this up and running in 10 minutes.

For this to work, your phone must be wifi enabled and connected to the same network as your PC. I use an iPhone in this example but any phone able to use wifi will work.

Here's what you need:

  • NirCmd: This command line utility is used to put the monitor into sleep. Download - Website
  • QuickPHP: You need to run a web server that supports PHP on your computer. Any server will work. I chose this one because it's lightweight and quick and easy to setup. QuickPHP- Website
  • PHP Source Code: Download
  1. After downloading NirCmd, unzip it and place nircmdc.exe in your system32 directory, i.e. C:\Windows\System32\. Note: Placing an executable in system32 directory is great because then you can access the files from any directory within command line, no need to find the directory first.
  2. Create two new folders. One for the PHP Server and one for your web files. I will use the following directories: C:\PHPServer and C:\PHP
  3. Download QuickPHP and unzip. This program will not install, you must place the program files somewhere. I moved them to C:\PHPServer for easy access.
  4. Download the source code and place it in C:\PHP.
  5. Go to the QuickPHP directory and run QuickPHP.exe - Change the "Root" folder to whatever you choose above as the web file directory (C:\PHP). Note the server port, default 5723.  Hit Start.
  6. For the next step you need to know your local IP address. To get this go to the start menu. Type in "Run" in the search bar and hit enter or simply click the run icon. Where it says "open" type in "cmd" - You now have a command prompt open. You should see something like C:\... type in "ipconfig" - Now look for your the number labeled IPv4 address. It will likely start with 192.168 - This is the number you will use in YOU_IP in the next step.
  7. Get your iPhone and open up Safari. In the address bar, type in http://YOUR_IP:5723 - i.e. http://192.168.1.2:5723
  8. Click the + sign and select "Add to Home Screen"
  9. Want to turn it off? Click:

There are a few ways this could be modified to better suit you: Modify the PHP code to only accept certain IP addresses. The PHP code is very simple and does not protect you from other people on your network turning your monitor off. That is why its useful to use a non-standard port and have a firewall on your network blocking outside traffic. - Alternatively, open a port on your firewall to allow outbound connections. Then use your WAN IP (www.whatismyip.com) to connect to the computer. This removes the need for the phone to be connected to wireless. - Change the filename to blah.php. It would prevent others from turning the monitor off because you then have to access http://YOU_IP:5723/blah.php

Filed under: Software Leave a comment
Comments (15) Trackbacks (2)
  1. Save yourself time and use a screen saver LOL

  2. haha yeah but then I would be waiting for hours. I could set it for one minute but then it shuts off too early when I’m watching a movie.

  3. For some reason, when I hit enter on my iphone, on my computer it says, cannot find ‘C:WindowsSystem32
    ircmd.exe’….But I have that program in the right place. So I don’t know why I can’t find it. Any solutions? ?

  4. @Taylor: It sounds like you modified the PHP file… it should be “nircmd.exe” and there should be slashes in the directory. Try using the PHP file as downloaded and see if that works.

  5. Im recommending to start program after boot by some parameter like:
    @start QuickPHP.exe /Minimized /Start /Port=80

  6. OR you could use ‘Bluetooth Proximity Lock’ (open source) to automatically turn on/off your screen wether your iPhone is near your PC or not.

  7. @mnt: Thanks! Just looked that up. Very cool. http://sourceforge.net/projects/btprox/

  8. Is there any way to do this with the server running on another computer in the network?

  9. There is not. Sorry.

  10. try mobilepcmonitor.com

  11. I am also getting the same problem as Taylor “cannot find ‘C:WindowsSystem32
    ircmd.exe’”

    I also have it in the right place and my php has not been touched. Thanks.. Windows 7 x64 tried both 32 & 64bit versions of NirCmd.

    Thanks for any help. I really want to see all 4 of my screens shut down while im chillin in bed. Almost better than The Clapper for sealing the deal with the lucky lady haha.

  12. Hi Sean. It may be an issue with slash characters. Try using this as the PHP code:

    < ?php
    $ip=@$REMOTE_ADDR;
    pclose(popen("start /B ". 'C:\\Windows\\System32\\nircmd.exe monitor off', "r"));
    echo 'Monitor Turned Off At ' .date("H:i:s");
    ?>

    Let me know how it works out!

  13. For those that get the message: can’t find ircmd.exe in system32. The tutorial states that you should put ircmdc.exe in this folder instead of ircmd.exe. At least, that solved it for me. :) I don’t know if both files have to be placed there though. Just my two cents. ;)

  14. cant get the file to execute and start the comand… help?


Leave a comment