tags:

views:

60

answers:

1
static void Main() 
{         
    // Set the SystemEvents class to receive event notification when a user 
    // when display settings change.
    SystemEvents.DisplaySettingsChanged += new 
        EventHandler(SystemEvents_DisplaySettingsChanged);        

    // For demonstration purposes, this application sits idle waiting for events.
    Console.WriteLine("This application is waiting for system events.");
    Console.WriteLine("Press <Enter> to terminate this application.");
    Console.ReadLine();
}

 private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
        {
   Console.WriteLine("Display setting change .");

}

i have created a windows service.when i restart the system and login then change the display setting it will not work and event is not fire but the service is runing.

when i restart the service then i change the display setting then display setting event fire.

i think SystemEvents.DisplaySettingsChanged may depend on some service.

A: 

The SystemEvents class uses the WTSSession APIs under the covers, which rely on the Terminal Services service (TermService). If your service messes with SystemEvents before that service is started, it will fail in interesting ways. If you make your service depend on TermService, the SystemEvents init should work by the time your service starts.

nitzmahone
yes i have done this i can capture SystemEvents.SessionSwitch event such as logon ,logoff ,lock and unlock at the first login time and work all right but SystemEvents.DisplaySettingsChanged is not fire when i change the setting .
Abdul jalil
What OS are you running? I believe Service Session 0 isolation will prevent it from working reliably on anything newer than 2003. See http://www.microsoft.com/whdc/system/vista/services.mspx
nitzmahone