如何识别窗口服务登录事件 [英] how to identify logon event in window service
问题描述
我有获得用户的详细信息,并将结果保存到日志文本文件中的窗口服务。并且,我的问题是,当我注销我的系统和IE浏览器再次登录,而无需重新启动机器..,我也想保存我登录我的系统到该日志文件中的时间.. 怎么能写在窗口服务的登录事件..请帮助的意见
我用下面code,但没有被写入日志文本文件的日志上。 即LogOn支持无1或登录NO-2 ...是否有任何错误或登录没得到足够的时间来完成这一过程。
Microsoft.Win32.SystemEvents.SessionSwitch + =新Microsoft.Win32.SessionSwitchEventHandler(SystemEvents_SessionSwitch);
无效SystemEvents_SessionSwitch(对象发件人,Microsoft.Win32.SessionSwitchEventArgs E)
{
StreamWriter的海峡=新的StreamWriter(D:\\ Log.txt文件,真正的);
str.WriteLine(登录无1:+ DateTime.Now.ToString());
str.Close();
如果(e.Reason == SessionSwitchReason.SessionLogon)
{
的StreamWriter STR1 =新的StreamWriter(D:\\ Log.txt文件,真正的);
str1.WriteLine(登录无-2:+ DateTime.Now.ToString());
str1.Close();
}
}
<一个href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.onsessionchange.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.onsessionchange.aspx
这可能是你最好的选择,因为Vista和Win7的处理用户会话很像一个终端服务器会。这应该让你处理会话的变化,并让相关信息的结构,如果你想会话ID或理由会改变(登录/注销/锁等)
i have a windows service that get user details and save the result into log text file. and, my problem is when i log off my system and login again ie without restarting the machine.., i also would like to save the time that i login my system into that log file.. How can write a login event in window service.. pls help with comments
I have used the below code, but nothing was written to the log text file on log on. ie LogOn no-1 or LogOn no-2... Is there any mistake or logon didnt get enough time to execute the process..
Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(SystemEvents_SessionSwitch);
void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
{
StreamWriter str = new StreamWriter("D:\\Log.txt", true);
str.WriteLine("LogOn no-1: " + DateTime.Now.ToString());
str.Close();
if (e.Reason == SessionSwitchReason.SessionLogon)
{
StreamWriter str1 = new StreamWriter("D:\\Log.txt", true);
str1.WriteLine("LogOn no-2: " + DateTime.Now.ToString());
str1.Close();
}
}
http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.onsessionchange.aspx
This may be your best bet, as Vista and Win7 handle the user sessions much like a terminal server would. This should let you handle session changes and it gives a structure with the relevant information, if you want session ID or reason for session change (logon / logoff / lock etc)
这篇关于如何识别窗口服务登录事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!