Solved

Hibernate PC

Posted on 2004-08-06
5
668 Views
Last Modified: 2008-01-09
I have been asked at work to develop something that will take computer off the network if a virus is detected. Good idea I though. I suggested the idea of just taking the machine off the network by disabling the network card (s) in the machine but they don’t want me to do that. They want the machine to be shutdown.

After much argument I have managed to get them to let me hibernate the machine, so that people don’t loose what they are working on (i.e. Developers loosing code, testers loosing test runs - that sort of thing). My question is this - How the hell do I hibernate a machine from C++, I can quite easily shut the bugger down but I have no idea how to hibernate it. Any ideas?

You help is much appreciated
0
Comment
Question by:ice_nin
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:ageraldnaveen
ID: 11733735
Which OS???

if it is windows, you shall use the SetSuspendState API available in powrprof.dll (Declared in Powrprof.h). Also make sure that, Hiberation is enabled in Windows (Control-Panel->Power Options->hibernate tab).

The prototype of SetSuspendState would be like,

BOOLEAN SetSuspendState(
  BOOL Hibernate,
  BOOL ForceCritical,
  BOOL DisableWakeEvent
);


You shall refer to MSDN for more info about each parameters (althou obvious).
0
 

Author Comment

by:ice_nin
ID: 11751229
I have included
#include <Powrprof.h> and added Powrprof.lib to the project and when i try and compile the application i get the following.
I have read the MSDN docs and they only mention the 2 files i have referenced.
Any ideas?

 error LNK2019: unresolved external symbol "unsigned char __stdcall SetSuspendState(unsigned char,unsigned char,unsigned char)" (?SetSuspendState@@YGEEEE@Z) referenced in function "void __cdecl HibernatePC(void)" (?HibernatePC@@YAXXZ)
0
 
LVL 1

Accepted Solution

by:
ageraldnaveen earned 125 total points
ID: 11751365
the linker error says "SetSuspendState" takes unsigned char as arg??? i doubt if you are using wrong header file..!! which is different from the import lib "powrprof.lib"

use shall try something like this..

typedef BOOL (*HibernateFn)(BOOL,BOOL,BOOL);

void myfunc()
{
      HMODULE hDLL = LoadLibrary("powrprof.dll");
      HibernateFn myfunc = (HibernateFn)GetProcAddress(hDLL,"SetSuspendState");
      myfunc(TRUE,FALSE,FALSE);
}

hope that helps..
0
 
LVL 1

Expert Comment

by:ageraldnaveen
ID: 11751386
correction in my prev. comment:

it shoud be

typedef BOOLEAN (*HibernateFn)(BOOLEAN,BOOLEAN,BOOLEAN);

sorry.
0
 

Author Comment

by:ice_nin
ID: 11751723
I have just looking into this error in more detail, i have found documents released by microsoft saying that they know about this and its an issue when compiling a C++ source file as opposed to a C source file.

They have no fix date for this but have given a temp fix for this

You need to edit the powrprof.h and add the following

//To the top of the File
#ifdef __cplusplus
extern "C" {
#endif

//To the bottom of the file
#ifdef __cplusplus
}  // extern "C"
#endif

Thanks for the help... I will assign you the points because the information was helpful
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question