Click on the Start button, type
cmd, and when
cmd.exe shows up, right click on it and click on "Run as administrator". Now you'll be seeing a command prompt with administrator rights.
Setting sleep options
On the Control Panel, look for "Change when the computer sleeps". On the "change settings for the plan:..." dialog, set the "Put the computer to sleep" option to a desired value (both in "on battery" and "plugged in" state).
Now click the "Change advanced power settings" link in the same dialog box. Click on "Sleep", click on "Allow waker timers", set it to "Disable".
Now click on "Multimedia settings", click on "When sharing media", click "Allow the computer to sleep".
Stoping devices from preventing sleep
On the command prompt, enter
Powercfg -devicequery wake_armed. This will show a list of devices that can prevent your computer from sleeping. You can remove a device from this list by using the command
Powercfg -devicedisablewake "devicename" (quotes included).