Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
AnswerRe: Wrapper class Pin
originSH12-Jul-07 4:05
originSH12-Jul-07 4:05 
GeneralRe: Wrapper class Pin
ramdil12-Jul-07 5:43
ramdil12-Jul-07 5:43 
GeneralRe: Wrapper class Pin
originSH12-Jul-07 6:02
originSH12-Jul-07 6:02 
GeneralRe: Wrapper class Pin
ramdil12-Jul-07 6:11
ramdil12-Jul-07 6:11 
GeneralRe: Wrapper class Pin
originSH12-Jul-07 6:30
originSH12-Jul-07 6:30 
GeneralRe: Wrapper class Pin
ramdil12-Jul-07 7:30
ramdil12-Jul-07 7:30 
GeneralRe: Wrapper class Pin
Zoltan Balazs12-Jul-07 9:34
Zoltan Balazs12-Jul-07 9:34 
QuestionHow do I capture an OnClosing type of event when Windows closes the app? Pin
eb3833512-Jul-07 3:46
eb3833512-Jul-07 3:46 
I have a single form application that runs in the systray. It is an audit trail logger that uses FileSystemWatcher to monitor file events in a directory. I can capture everything that I am looking to capture except when someone logs off the computer.

I tried using the Form1_Closing method, but it doesn't seem to activate when Windows is closing the application when a user logs off or shuts down the computer. Am I missing something?

Here is my code for the Form1_Closing method. I have no code pointing to this method, I just assume it finds the method when the application closes.

private void Form1_Closing(object sender, FormClosedEventArgs e)<br />
     <br />
        {<br />
            MessageBox.Show("Closing Form");<br />
<br />
            string _userName = Environment.UserName;<br />
            string _date = DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss");<br />
            string _eventType = "Logged Off";<br />
            RegistryKey _regKey = Registry.LocalMachine;<br />
            RegistryKey _subRegKey = _regKey.OpenSubKey("Software\\LAT_Systray");<br />
            string _fileName = Convert.ToString(_subRegKey.GetValue("File_Name"));<br />
<br />
            XmlDocument _xmlDoc = new XmlDocument();<br />
<br />
            _xmlDoc.Load(_fileName);<br />
<br />
            //Create new Event Node in XML file<br />
            XmlElement _newEvent = _xmlDoc.CreateElement("Event");<br />
<br />
            //Create new Element time stamp in XML file "Event" node<br />
            XmlElement _newDateNode = _xmlDoc.CreateElement("EventTime");<br />
            _newDateNode.InnerText = _date;<br />
            _newEvent.AppendChild(_newDateNode);<br />
<br />
            //Create new Element UserName in XML file "Event" node<br />
            XmlElement _newUserNode = _xmlDoc.CreateElement("UserName");<br />
            _newUserNode.InnerText = Environment.UserName;<br />
            _newEvent.AppendChild(_newUserNode);<br />
<br />
            //Create new Element EventType in XML file "Event" node<br />
            XmlElement _newTypeNode = _xmlDoc.CreateElement("EventType");<br />
            _newTypeNode.InnerText = _eventType;<br />
            _newEvent.AppendChild(_newTypeNode);<br />
<br />
            //Insert after last child "Event" node in file<br />
            _xmlDoc.DocumentElement.InsertAfter(_newEvent, _xmlDoc.DocumentElement.LastChild);<br />
<br />
            //closes the file<br />
            FileStream _fsxml = new FileStream(_fileName, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);<br />
            _xmlDoc.Save(_fsxml);<br />
            _fsxml.Close();<br />
<br />
        }


Any help is greatly appreciated as you know.

Jeff
IT by necessity only
AnswerRe: How do I capture an OnClosing type of event when Windows closes the app? Pin
Luc Pattyn12-Jul-07 4:25
sitebuilderLuc Pattyn12-Jul-07 4:25 
GeneralRe: How do I capture an OnClosing type of event when Windows closes the app? Pin
eb3833512-Jul-07 4:39
eb3833512-Jul-07 4:39 
GeneralRe: How do I capture an OnClosing type of event when Windows closes the app? Pin
Luc Pattyn12-Jul-07 5:02
sitebuilderLuc Pattyn12-Jul-07 5:02 
QuestionProblem in running the Instant messaging program having TCP client and server Pin
vrani12-Jul-07 2:24
vrani12-Jul-07 2:24 
AnswerRe: Problem in running the Instant messaging program having TCP client and server Pin
Christian Graus12-Jul-07 2:29
protectorChristian Graus12-Jul-07 2:29 
GeneralRe: Problem in running the Instant messaging program having TCP client and server Pin
vrani12-Jul-07 2:42
vrani12-Jul-07 2:42 
GeneralRe: Problem in running the Instant messaging program having TCP client and server Pin
Christian Graus12-Jul-07 3:05
protectorChristian Graus12-Jul-07 3:05 
QuestionThe magic of TransactionScope Pin
Le centriste12-Jul-07 1:45
Le centriste12-Jul-07 1:45 
JokeRe: The magic of TransactionScope Pin
Luc Pattyn12-Jul-07 1:53
sitebuilderLuc Pattyn12-Jul-07 1:53 
JokeRe: The magic of TransactionScope Pin
Le centriste12-Jul-07 1:54
Le centriste12-Jul-07 1:54 
GeneralRe: The magic of TransactionScope Pin
Martin#12-Jul-07 1:59
Martin#12-Jul-07 1:59 
AnswerRe: The magic of TransactionScope Pin
Christian Graus12-Jul-07 2:41
protectorChristian Graus12-Jul-07 2:41 
GeneralRe: The magic of TransactionScope Pin
Martin#12-Jul-07 2:47
Martin#12-Jul-07 2:47 
GeneralRe: The magic of TransactionScope Pin
Le centriste12-Jul-07 2:51
Le centriste12-Jul-07 2:51 
AnswerRe: The magic of TransactionScope Pin
Pete O'Hanlon12-Jul-07 2:49
mvePete O'Hanlon12-Jul-07 2:49 
GeneralRe: The magic of TransactionScope Pin
Le centriste12-Jul-07 2:53
Le centriste12-Jul-07 2:53 
AnswerRe: The magic of TransactionScope Pin
Judah Gabriel Himango12-Jul-07 5:05
sponsorJudah Gabriel Himango12-Jul-07 5:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.