Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Hibernate PC

Posted on 2004-08-06
5
Medium Priority
?
695 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 375 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

730 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