Skip to content

How to respond to system shutdown??

Jia En

Asked Jan 16, 2006, 9:35 PM EST2 answers
Share
LinkedInX

I have created a console application, and I used the code below to get the respond from the system shutdown.. But it don't seems to be working.. And I owaz get this error

c:\jia en\tcp\client_standalone\client.cs(96,27): error CS0115: 'Client.Client.WndProc(ref System.Windows.Forms.Message)': no suitable method found to override


Please HELP me.. Thankz..

protected override void WndProc(ref System.Windows.Forms.Message m)

{

if(m.Msg==WM_QUERYENDSESSION)

{

isShuttingDown=true;

}

base.WndProc(ref m);

}

private void Client_Closing(object sender, System.ComponentModel.CancelEventArgs e)

{

if(isShuttingDown)

{

e.Cancel=false;

isShuttingDown = false;

string endTime = GetTime();

#region Display client's machine name

System.Security.Principal.WindowsPrincipal wp = new

System.Security.Principal.WindowsPrincipal

C#
(System.Security.Principal.WindowsIdentity.GetCurrent());
c.machName = wp.Identity.Name;
Console.WriteLine(c.machName);
#endregion
#region List all the processes running in client machine
Process[] procs = Process.GetProcesses( Environment.MachineName );

foreach (Process process in procs)
{
// Store all the processes in procName
c.procName = process.ProcessName + "\n";
Console.WriteLine(c.procName);
}
#endregion
writeToFile();
}
}

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Wondering where you have copied that... But WndProc is System.Windows.Forms.Control method, so how on earth would you override it in a console program with no controls in it at all? Always search MSDN library first!

    WM_QUERYENDSESSION is not defined, so that needs to be defined too (it's 0x0011 by the way).

    0
  • 0
    I did declared WM_QUERYENDSESSION in the top part of my program.. In my client console, I need to the app to respond to system shutdown.. Sjould is it possible for console app to do it?
    0