公交车上荫蒂添的好舒服的电影-公用玩物(np双xing总受)-公用小荡货芊芊-公与妇仑乱hd-攻把受做哭边走边肉楼梯play-古装一级淫片a免费播放口

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

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

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

:【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

主站蜘蛛池模板: 99久久久国产精 | 国产爆乳无码视频在线观 | 国产在线观看码高清视频 | 国产精品自产拍在线观看网站 | 国产午夜精品免费视频观看 | 国产麻豆精品传媒av | 国产精品无码mv在线观看 | 国产三级精品视频 | 国产精品传媒秘入口麻豆 | 国产成人精品午夜福利在线观看 | 97精品无码永久在线 | 国产黄色二级片 | 国产精品www视频免费看 | 精品国产福利在线观看麻豆 | 国产成人av福利在线播放 | 国内真实愉拍系列在线 | 国产麻豆剧传媒精品网站 | 精品日韩欧美人妻少妇 | 精品亚洲一区二区不卡 | 国产在线精品一区二区在线观看 | 91精品云霸高清中文字幕 | 精品高清国产一区二区三区四区 | 国产午夜成人av在线播放 | 国产高清美女**毛片 | 国产成人高清激情视频在线观看 | 国产偷窥盗摄一区二区 | 91在线播放国产日本欧美 | 国产极品粉嫩福利姬萌白酱 | 成在人钱av无码免费高潮喷水 | 91亚洲成色精品一区二区三区 | av喷水高潮喷水在线观看com | 国产成人综合亚洲亚洲欧美 | 精品无码欧美黑人又粗又 | av在线不卡无码 | 国产高清在线精品一本大道 | 国产不卡av暴操 | 国产在线第一区二 | 国产自拍电影天堂 | 国产福利片一 | 国产喷水吹潮视频在线播放 | 国产精品免费福利久久 |