473,418 Members | 2,091 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

SystemEvents.SessionEnding not working

Hi All,

Iam using WMI for the first time and am trying to detect and stop a
user login event. But when i run my code, i notice that the event
handler is not getting called. Can some one tell me where Iam going
wrong?

Thanks a million,
Roshan

The code i used is as follows

using Microsoft.Win32;
using System;
using System.IO;
using System.Management;

namespace myWmi
{
public class WMITest
{
public static void Main(String[] args)
{
WMITest wm= new WMITest();

// Register the event handler
SystemEvents.SessionEnding += new
SessionEndingEventHandler(ShutdownStarted);

// Wait for a logout/shutdown event
Console.WriteLine("Waiting for Events");
Console.ReadLine();
}

static void ShutdownStarted(object sender,
SessionEndingEventArgs e)
{
e.Cancel = true;
Console.WriteLine("In SessionEndingEventHandler");
using(StreamWriter sw = new
StreamWriter("C:\\Shutdown.txt"))
{
sw.WriteLine("System is going down for a
{0}.",e.Reason.ToString());
sw.WriteLine("Cancelling End of session");
}
}
}// End of class WMITest
}// End of namespace

Nov 17 '05 #1
0 2838

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Defiant | last post by:
Has anyone used SystemEvents.InvokeOnEventsThread? The MSDN documentation is a little vague with regards this method. I am trying to detect and respond to changes to the desktop (like moving...
0
by: Ivan | last post by:
Hi, members, Does anyone know how to use SystemEvents in namespace Microsoft.Win32? Could I use it to gather the system event when a usb device is plugged? Could you provide a sample code to...
6
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
9
by: esafran | last post by:
Hi, I've have encountered a very strange behaviour under C#. My application is registering for: Microsoft.Win32.SystemEvents.DisplaySettingsChanged &...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
5
by: bbembi_de | last post by:
Hello everyone, I'm listening to the SessionEnding event, so I can close my application properly when Windows is shutting down. I do some disposing and stuff if the event occurrs but windows...
4
by: Adam Benson | last post by:
Hi, We have an app which, every now and then, has very high CPU usage. Profiling under perfmon shows it to be thread #3 which is running at >=95%. I took a process dump and looked at thread #3...
2
by: Bandu | last post by:
Hi, I used SystemEvents.PowerModeChanged to monitor from WinForm application and it work fine. I put that code in to Windows service application and it not seem to catch any power event. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.