I like to fall asleep while listening music, but, I don’t like when it runs all night long.
Since now, I used the command line “shutdown -s -t 3600” in a .bat file.
But sometimes, I don’t want to turn my computer off because I have things running, or files downloading…
Then I discovered nircmd, wich is a must have! It’s a soft that allows a lot of fun and useful commands, really easily! If you don’t know it already, you must have a look here. So I wrote a small code which let’s you choose between turning your computer off, or just muting it after the time you entered.
My code needs nircmd.exe in C:\Windows.
Here is the code i wrote in C:
#include <windows.h> #include <stdio.h> #include <stdlib.h> int main() { int minutes=0; char entry=0; char command_line[64]=""; /*print title*/ printf("===== WINDOWS MUSIC SLEEP MODE =====\n"); /*Shutdown or mute Mode*/ do { fflush(stdin); printf("Do you want to mute or shutdown the computer ? [M/S]\n"); scanf("%c",&entry); }while(entry!='m'&& entry!='M' && entry!='s' && entry!='S'); if(entry=='m'||entry=='M') { fflush(stdin); printf("In how many minutes, do you want to mute your computer?\n"); scanf("%d",&minutes); printf("Computer will be muted in %d minute.\nYou can exit\n",minutes); /*prepare the command line*/ sprintf(command_line,"nircmd.exe cmdwait %d mutesysvolume 1",(60000*minutes)); } else { fflush(stdin); printf("In how many minutes, do you want to shutdown your computer?\n"); scanf("%d",&minutes); printf("Computer will be shutdown in %d minute.\nYou can exit\n",minutes); /*prepare the command line*/ sprintf(command_line,"nircmd.exe cmdwait %d exitwin poweroff",60000*minutes); } /*execute the command line*/ system(command_line); system("PAUSE"); }
Leave a Reply