PDA

View Full Version : Detecting and stopping hibernation and standby



motionman95
November 1st, 2008, 01:49 PM
I read somewhere that I could use something called WM_POWERBROADCAST, but I have yet to see any code online that implements it, and I'm toooo inexperienced to try and convert vb to c# (All I get is a headache). Has anyone here ever worked on something similar and could help me?

Thanks and much appreciated!

kirupa
December 3rd, 2008, 10:51 PM
You could look into sending WM messages. This post gives you a basic example of that working: http://blog.kirupa.com/?p=77

:)

motionman95
January 1st, 2009, 10:57 PM
You could look into sending WM messages. This post gives you a basic example of that working: http://blog.kirupa.com/?p=77

:)

Thanks Kirupa! Could I use that to send the system BROADCAST_QUERY_DENY? Thanks again!

kirupa
January 1st, 2009, 11:33 PM
Any message can be sent using that approach, but the number of arguments messages take vary, so be sure you take that into account. The following site can help you out: http://www.pinvoke.net

:)

motionman95
January 1st, 2009, 11:47 PM
Any message can be sent using that approach, but the number of arguments messages take vary, so be sure you take that into account. The following site can help you out: http://www.pinvoke.net

:)

I searched for standby and what came up didn't help me. :bored:

blacklizard
May 30th, 2009, 02:00 AM
I did an application which shuts down the pc after a timer expires. Maybe it could help i am giving u the source code.

using System.Management;

public static void Shutdown()
{
ManagementScope Scope = null;
ConnectionOptions ConnOptions = null;
ObjectQuery ObjQuery = null;
ManagementObjectSearcher ObjSearcher = null;
try
{
ConnOptions = new ConnectionOptions();
ConnOptions.Impersonation = ImpersonationLevel.Impersonate;
ConnOptions.EnablePrivileges = true;
//local machine
//if (machineName.ToUpper() == Environment.MachineName.ToUpper())
Scope = new ManagementScope(@"\ROOT\CIMV2", ConnOptions);

//else
//{
// //remote machine
// ConnOptions.Username = username;
// ConnOptions.Password = password;
// Scope = new ManagementScope(@"\\" + machineName + @"\ROOT\CIMV2", ConnOptions);
//}
Scope.Connect();
ObjQuery = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
ObjSearcher = new ManagementObjectSearcher(Scope, ObjQuery);
foreach (ManagementObject operatingSystem in ObjSearcher.Get())
{
//MessageBox.Show("Caption = " + operatingSystem.GetPropertyValue("Caption"));
//MessageBox.Show("Version = " + operatingSystem.GetPropertyValue("Version"));
ManagementBaseObject outParams = operatingSystem.InvokeMethod("Shutdown", null, null);

}
}
catch (Exception ex)
{
throw ex;
}
}