Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Windows from going to sleep while building solution?

I would like if while building a solution my system wouldn't go to sleep, exactly like while watching movies, but after it's finished it would go to sleep like normally. And I didn't want to disable the sleep after 20 minutes from the power options.

Is there a solution for this like a short script perhaps that would execute a cmd command and prevent going to sleep for the duration of the command?

like image 565
sekmet64 Avatar asked Nov 03 '22 09:11

sekmet64


1 Answers

You can create a vbscript file called "nosleep.vbs"

    Set osShell = CreateObject("Wscript.Shell")
    thecmd = " powercfg.exe /change ""always on"" /monitor-timeout-ac 20"
    osShell.Run "cmd " & thecmd

In Visual Studio you can call this nosleep.vbs code.

You can do this in the pre-build and post-build steps.

I am assuming you are running Visual Studio as administrator.

Depending on the OS Version, the parameters vary.

You can get more info here

    http://technet.microsoft.com/en-us/library/cc748940(v=WS.10)
like image 149
Bruno Avatar answered Nov 09 '22 10:11

Bruno