private void button1_Click(object sender, EventArgs e)
{
EventLog rEvent = new EventLog();
rEvent.Log = "Security"; //"Application", "Security", "System"
//rEvent.MachineName = "dn0351";
int tmpNum = 0;
foreach (EventLogEntry entry in rEvent.Entries)
{
if (tmpNum>5) { return; }
//if (entry.EventID == 4778 && checkMessageLogin(entry.Message))
//if (entry.EventID == 4624 || entry.EventID == 4778)
if (entry.EventID == 4778)
{
tmpNum++;
Console.WriteLine($"第 {tmpNum} 次登錄");
textBox1.Text = textBox1.Text + Environment.NewLine;
textBox1.Text = textBox1.Text + Environment.NewLine;
textBox1.Text = textBox1.Text + Environment.NewLine;
textBox1.Text = textBox1.Text +$"第 {tmpNum} 次登錄:" + Environment.NewLine;
textBox1.Text = textBox1.Text + ("時間:" + entry.TimeGenerated) + Environment.NewLine;
textBox1.Text = textBox1.Text + ("索引:"+entry.Index) + Environment.NewLine;
textBox1.Text = textBox1.Text + ("ID:" + entry.EventID) + Environment.NewLine;
textBox1.Text = textBox1.Text + ("用戶名:" + entry.UserName) + Environment.NewLine;
textBox1.Text = textBox1.Text + ("設備名稱:" + entry.MachineName) + Environment.NewLine;
textBox1.Text = textBox1.Text + ("站點:" + entry.Site) + Environment.NewLine;
textBox1.Text = textBox1.Text + ("來源:" + entry.Source) + Environment.NewLine;
textBox1.Text = textBox1.Text + ("所有信息:" + entry.Message) + Environment.NewLine;
//textBox1.Text = textBox1.Text + Environment.NewLine + entry.Message;
}
}
}
public Boolean checkMessageLogin(String Msg)
{
Regex check = new Regex(@"登錄類型:\s*(?:2|10)", RegexOptions.IgnoreCase);
if (check.IsMatch(Msg))
{
return true;
}
else
{
return false;
}
}