午夜视频在线观看区二区-午夜视频在线观看视频-午夜视频在线观看视频在线观看-午夜视频在线观看完整高清在线-午夜视频在线观看网站-午夜视频在线观看亚洲天堂

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

【C#】讀取Windows系統事件查看器中最新遠程桌面用戶成功或失敗登陸記錄

admin
2025年2月18日 15:47 本文熱度 654

:【C#】讀取Windows系統事件查看器中最新遠程桌面用戶成功或失敗登陸記錄

查詢時,需要注意事件查看器中的各個狀態碼和相應內容,根據內容靈活設計需要提取的內容:

DateTime startDate = new DateTime(2025, 2, 15); // 例如,從2023年1月1日開始

EventLog eventLog = new EventLog();

eventLog.Log = "Security"; // 可以更改為 "System" 或 "Security" 等

eventLog.Source = "Application"; // 根據需要設置,通常為應用程序名稱或"Application"

                                 // 獲取所有條目

var entries = eventLog.Entries;


// 過濾出指定日期后的條目

var filteredEntries = entries.Cast<EventLogEntry>()

                             .Where(e => e.TimeGenerated > startDate)

                             .ToList();

int tmpNum = 0;

foreach (var entry in filteredEntries)

{

    //Console.WriteLine($"Time: {entry.TimeGenerated}, Message: {entry.Message}");

    if (entry.EventID == 4624 || entry.EventID == 4625 || entry.EventID == 4778)

    {

        tmpNum++;

        // 解析用戶信息,這里簡單地從消息中提取用戶名,不同系統的事件消息格式可能略有不同,需根據實際情況調整解析邏輯

        string message = entry.Message;

        string tmpMessage = message;

        int startIndex = 0;

        int endIndex = 0;

        if (entry.EventID == 4624 || entry.EventID == 4625)

        {

            string tmpFirstStr = "";

            if (entry.EventID == 4624) { tmpFirstStr = "新登錄:"; }

            if (entry.EventID == 4625) { tmpFirstStr = "登錄失敗的帳戶:"; }

            startIndex = message.IndexOf(tmpFirstStr) + tmpFirstStr.Length;

            tmpMessage = message.Substring(startIndex, message.Length - startIndex);

        }


        //獲取登錄用戶名

        string latestLoginUser = string.Empty;

        string tmpUserNameInfo = "";

        if (entry.EventID == 4778 || entry.EventID == 4625) { tmpUserNameInfo = "帳戶名:"; }

        if (entry.EventID == 4624) { tmpUserNameInfo = "帳戶名稱:"; }

        startIndex = tmpMessage.IndexOf(tmpUserNameInfo) + tmpUserNameInfo.Length;

        endIndex = tmpMessage.IndexOf(Environment.NewLine, startIndex);

        if (startIndex > 0 && endIndex > startIndex)

        {

            latestLoginUser = tmpMessage.Substring(startIndex, endIndex - startIndex).Trim();

        }


        //獲取登錄IP地址

        string latestLoginIP = string.Empty;

        string tmpUserIpInfo = "";

        if (entry.EventID == 4624 || entry.EventID == 4625) { tmpUserIpInfo = "源網絡地址:"; }

        if (entry.EventID == 4778) { tmpUserIpInfo = "客戶端地址:"; }

        startIndex = tmpMessage.IndexOf(tmpUserIpInfo) + tmpUserIpInfo.Length;

        endIndex = tmpMessage.IndexOf(Environment.NewLine, startIndex);

        if (startIndex > 0 && endIndex > startIndex)

        {

            latestLoginIP = tmpMessage.Substring(startIndex, endIndex - startIndex).Trim();

        }


        //登錄結果

        string tmpLoginResult = "";

        if (entry.EventID == 4778 || entry.EventID == 4624) { tmpLoginResult = "成功。"; }

        if (entry.EventID == 4625)

        {

            tmpLoginResult = "失敗。";

            string tmpErrorInfo = " 失敗原因:";

            startIndex = tmpMessage.IndexOf(tmpErrorInfo) + tmpErrorInfo.Length;

            endIndex = tmpMessage.IndexOf(Environment.NewLine, startIndex);

            if (startIndex > 0 && endIndex > startIndex)

            {

                tmpLoginResult = tmpErrorInfo + tmpMessage.Substring(startIndex, endIndex - startIndex).Trim();

            }

        }


        Console.WriteLine($"第 {tmpNum} 次登錄(" + entry.EventID + ",時間:" + entry.TimeGenerated);

        Console.WriteLine("登錄帳戶名:" + latestLoginUser);

        Console.WriteLine("登錄IP地址:" + latestLoginIP);

        Console.WriteLine("登錄結果:" + tmpLoginResult);

    }

}

操作結果如下:


該文章在 2025/2/18 15:47:58 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 国产精品爆乳奶水无码视频免費 | 成人丝袜激情一区二区 | 国产人妖高清一区二区 | 国产精品白丝av网站在线观看 | 国产成人综合亚洲网站 | 国产精品无码久久av不卡 | 国内福利在线视频 | 91福利国产在线在线播放 | 国产成人a区在线观看视频 国产成人a人 | 国产一区二区精品高清在线观看 | 成人精品久久中文字幕 | 91精品国产偷窥一区二区 | 国产av无码免费一区二区 | 国产精品一区二区三区99 | 国产偷录视频叫床高潮 | 国产欧美精品综合一区 | 国产91丝袜在线播放九色 | 2025亚洲韩国精品乱码 | 国产成a人亚洲精v品无码 | 91精品福利麻豆专区 | 国自产成人免费视频在线播放 | 国产无套露面在线 | 国产精品一区福利 | 国产日韩高清制服一区 | 91国在线啪精品一区 | 国产精口品美女乱子伦高潮 | 国产三级片免费人 | 国产精品毛片aⅴ一区二区三区 | 国产看片一区二区三 | 国产三级在线观看免费播放 | 国产99er66在线视频 | 国产成人综合在线视 | 国产极品粉嫩美女在线播放 | 精品国产一级久久 | 国产精品亚洲成在人线 | 精品一区二区女厕 | 国产美女流出白浆在线观看 | 91精品国产乱码在线观看 | 国产精品精品国产一区二区 | 国产人妻精品一区二区三区不 | 成人国产一区二区三区精品不卡 |