Jump to content

How to hibernate PC without any CMD window popping up, using either CMD, or WINAPI in C++?

ClobberXD

I believe functions like ExitWindowsEx exist within WINAPI to shutdown the system completely, but I'm not able to find a corresponding function to hibernate the PC.

 

Condition: I don't want a small CMD window popping up when I execute file, so 'system()' is out of scope...

Nothing to see here ;)

Link to comment
Share on other sites

Link to post
Share on other sites

Maybe send a keyboard shortcut?

Main Gaming Rig:

Spoiler

Core i7-4770, Cryorig M9i Cooler, ASUS B85M GAMER, 8GB HyperX Fury Red 2x4GB 1866MHz, KFA2 GTX 970 Infin8 Black Edition "4GB", 1TB Seagate SSHD, 256GB Crucial m4 SSD, 60GB Corsair SSD for Kerbal and game servers, Thermaltake Core V21 Case, EVGA SuperNOVA 650W G2.

Secondary PC:

Spoiler

i5-2500k OCed, Raijintek Themis, Intel Z77GA-70K, 8GB HyperX Genesis in grey, GTX 750 Ti, Gamemax Falcon case.

 

Link to comment
Share on other sites

Link to post
Share on other sites

could you not use 

 

shutdown -s -f -t 0

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

24 minutes ago, vorticalbox said:

could you not use 

 


shutdown -s -f -t 0

 

That uses CMD, which would pop up a command window. Which the OP said they didn't want.

Main Gaming Rig:

Spoiler

Core i7-4770, Cryorig M9i Cooler, ASUS B85M GAMER, 8GB HyperX Fury Red 2x4GB 1866MHz, KFA2 GTX 970 Infin8 Black Edition "4GB", 1TB Seagate SSHD, 256GB Crucial m4 SSD, 60GB Corsair SSD for Kerbal and game servers, Thermaltake Core V21 Case, EVGA SuperNOVA 650W G2.

Secondary PC:

Spoiler

i5-2500k OCed, Raijintek Themis, Intel Z77GA-70K, 8GB HyperX Genesis in grey, GTX 750 Ti, Gamemax Falcon case.

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, NinjaJc01 said:

That uses CMD, which would pop up a command window. Which the OP said they didn't want.

but it would shut down right away so you probably wouldn't even see it.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

If you use CreateProcess (part of the WinAPI, so #include <Windows.h> first) with dwCreationFlags (the 6th parameter) set to CREATE_NO_WINDOW, it will run the program with no UI.

STARTUPINFO si;
PROCESS_INFORMATION pi;
CreateProcess (L"shutdown", L"/h /t 0", NULL, NULL, false, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);

Note, I've not tested this code, and it's been a while since I've used the WinAPI, but it's based on a combination of the answers on http://stackoverflow.com/questions/780465/winapi-createprocess-but-hide-the-process-window, as well as the documentation, and my vague memory of having done this before, a while ago. You will probably have to modify it slightly to make it work correctly.

 

EDIT: The answer above is much better, and I would recommend using the designated WinAPI function rather than running the command where possible.

HTTP/2 203

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, colonel_mortis said:

If you use CreateProcess (part of the WinAPI, so #include <Windows.h> first) with dwCreationFlags (the 6th parameter) set to CREATE_NO_WINDOW, it will run the program with no UI.


STARTUPINFO si;
PROCESS_INFORMATION pi;
CreateProcess (L"shutdown", L"/h /t 0", NULL, NULL, false, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);

Note, I've not tested this code, and it's been a while since I've used the WinAPI, but it's based on a combination of the answers on http://stackoverflow.com/questions/780465/winapi-createprocess-but-hide-the-process-window, as well as the documentation, and my vague memory of having done this before, a while ago. You will probably have to modify it slightly to make it work correctly.

 

EDIT: The answer above is much better, and I would recommend using the designated WinAPI function rather than running the command where possible.

Does it show a CMD window?

Main Gaming Rig:

Spoiler

Core i7-4770, Cryorig M9i Cooler, ASUS B85M GAMER, 8GB HyperX Fury Red 2x4GB 1866MHz, KFA2 GTX 970 Infin8 Black Edition "4GB", 1TB Seagate SSHD, 256GB Crucial m4 SSD, 60GB Corsair SSD for Kerbal and game servers, Thermaltake Core V21 Case, EVGA SuperNOVA 650W G2.

Secondary PC:

Spoiler

i5-2500k OCed, Raijintek Themis, Intel Z77GA-70K, 8GB HyperX Genesis in grey, GTX 750 Ti, Gamemax Falcon case.

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, NinjaJc01 said:

Does it show a CMD window?

Neither my method, nor the one above mine, should show a CMD window.

HTTP/2 203

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, colonel_mortis said:

Neither my method, nor the one above mine, should show a CMD window.

Ok, so that sounds like it would likely work.

Main Gaming Rig:

Spoiler

Core i7-4770, Cryorig M9i Cooler, ASUS B85M GAMER, 8GB HyperX Fury Red 2x4GB 1866MHz, KFA2 GTX 970 Infin8 Black Edition "4GB", 1TB Seagate SSHD, 256GB Crucial m4 SSD, 60GB Corsair SSD for Kerbal and game servers, Thermaltake Core V21 Case, EVGA SuperNOVA 650W G2.

Secondary PC:

Spoiler

i5-2500k OCed, Raijintek Themis, Intel Z77GA-70K, 8GB HyperX Genesis in grey, GTX 750 Ti, Gamemax Falcon case.

 

Link to comment
Share on other sites

Link to post
Share on other sites

22 hours ago, Unimportant said:

 

21 hours ago, colonel_mortis said:

If you use CreateProcess (part of the WinAPI, so #include <Windows.h> first) with dwCreationFlags (the 6th parameter) set to CREATE_NO_WINDOW, it will run the program with no UI.


STARTUPINFO si;
PROCESS_INFORMATION pi;
CreateProcess (L"shutdown", L"/h /t 0", NULL, NULL, false, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);

Note, I've not tested this code, and it's been a while since I've used the WinAPI, but it's based on a combination of the answers on http://stackoverflow.com/questions/780465/winapi-createprocess-but-hide-the-process-window, as well as the documentation, and my vague memory of having done this before, a while ago. You will probably have to modify it slightly to make it work correctly.

 

EDIT: The answer above is much better, and I would recommend using the designated WinAPI function rather than running the command where possible.

Thank you guys! I'll try it out right now! :)

 

@colonel_mortis BTW, although I'm following this topic, I wasn't even notified about any reply, and when I incidentally came across this topic, I was flabbergasted to see 9 replies to it! Just bringing it to your attention.

Nothing to see here ;)

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Anand_Geforce said:

 

Thank you guys! I'll try it out right now! :)

 

@colonel_mortis BTW, although I'm following this topic, I wasn't even notified about any reply, and when I incidentally came across this topic, I was flabbergasted to see 9 replies to it! Just bringing it to your attention.

You don't appear to be following this topic, which would be why you're not getting notifications. If you go to Notification Settings, you can enable automatic following of topics that you start.

HTTP/2 203

Link to comment
Share on other sites

Link to post
Share on other sites

15 hours ago, colonel_mortis said:

You don't appear to be following this topic, which would be why you're not getting notifications. If you go to Notification Settings, you can enable automatic following of topics that you start.

Oops, I accidentally toggled that switch while modifying my notification settings... Thanks!

Nothing to see here ;)

Link to comment
Share on other sites

Link to post
Share on other sites

You know, I hate to be that guy, but I would really like to know what project @Anand_Geforce is working on? In the past you've asked about anything from snooping graphics to watching keyboard strokes, to this. If I didn't know any better, I'd say that all the things you're asking for are being used with malice intent.

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

On 27/7/2016 at 0:05 AM, straight_stewie said:

You know, I hate to be that guy, but I would really like to know what project @Anand_Geforce is working on? In the past you've asked about anything from snooping graphics to watching keyboard strokes, to this. If I didn't know any better, I'd say that all the things you're asking for are being used with malice intent.

Nothing like that! All of my doubts and questions pertain to different projects, most of which are incomplete, as I'm a total beginner (but learning fast) to C++. But the basis of all these apparently unrelated doubts, and questions are due to my deep interest in, and extreme passion for C++.

 

Here are a few of the major projects I am (or was) working on:

  • FPS Overlay - I could've just used FRAPS - but then again, I want to know how it is implemented, how it captures frames, how an overlay is drawn, etc. (curiosity!)
  • CPU Benchmarking Tool (Prototype) - I love hardware, I love software - this is the best of both!
  • File Compression - Again, wanted to know how it works...
  • Keylogger
  • Simple file copy tool (at the very birth of the developer in me - big deal as all I knew was cin and cout)

The Hibernate PC project is nothing but a simple way of hibernating the PC in one-click, but the CMD window popping up looks plain ugly, and the code itself consists of just the SetSuspendState(TRUE,FALSE,FALSE); statement in WinMain, without creating any window for the application itself.

 

I really do appreciate your concern, but don't worry - as you can see for yourself, there is no malicious intent at all! Thanks a ton! :)

Nothing to see here ;)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×