From 164a1b4891f3fbe019ea897738407d8f54d5dda6 Mon Sep 17 00:00:00 2001 From: S0cke3t <1510536500@qq.com> Date: Thu, 4 Jan 2024 21:30:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=A4=84=E7=90=86=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Main.cs | 105 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 84 insertions(+), 21 deletions(-) diff --git a/Main.cs b/Main.cs index 1f74614..e222c37 100644 --- a/Main.cs +++ b/Main.cs @@ -21,6 +21,7 @@ public Main() { InitializeComponent(); } + string currentDirectory = AppDomain.CurrentDomain.BaseDirectory; XmlNodeList xmlNodeList; XmlDocument xmlDocument; XmlElement xmlElement; @@ -35,6 +36,53 @@ private XmlDocument ReadXml(string xmlpath) { return xmlDocument; } + private string GetResultByMark(string mark) { + /*// 要执行的命令 + string command = "type config.cfg | findstr "; + // 创建一个新的进程启动信息 + ProcessStartInfo processStartInfo = new ProcessStartInfo + { + FileName = "cmd.exe", + RedirectStandardInput = true, + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + WindowStyle = ProcessWindowStyle.Hidden, + Arguments = "/c " + command + mark, + WorkingDirectory = currentDirectory + }; + // 创建进程对象 + Process process = new Process + { + StartInfo = processStartInfo + }; + try + { + // 启动进程 + process.Start(); + // 获取命令输出 + string output = process.StandardOutput.ReadToEnd().Split("=")[1]; + // 等待进程执行完成 + process.WaitForExit(); + + // 打印输出结果 + return output; + } + catch (Exception ex) + { + UIMessageBox.ShowError(ex.Message); + return null; + } + finally + { + // 关闭进程 + process.Close(); + process.Dispose(); + }*/ + return ""; + //TODO + } + private void AboutLinkLabel_Click(object sender, EventArgs e) { Process.Start("https://github.com/DeEpinGh0st/WindowsBaselineAssistant"); @@ -64,31 +112,46 @@ private void CheckBtn_Click(object sender, EventArgs e) BaselineList.Rows[index].Cells[dataColumn.Ordinal + 2].Value = "不符合"; } }*/ - xmlDocument = ReadXml(@"D:\Projects\C#\WindowsBaselineAssistant\bin\Debug\item.xml"); - if (xmlDocument != null) + xmlDocument = ReadXml(currentDirectory+ @"\item.xml"); + if (xmlDocument == null) { - BaselineList.Rows.Clear(); - xmlElement = xmlDocument.DocumentElement; - xmlNodeList = xmlElement.ChildNodes; - foreach (XmlNode xmlNode in xmlNodeList) + UIMessageBox.ShowError("未找到配置文件"); + return; + } + BaselineList.Rows.Clear(); + xmlElement = xmlDocument.DocumentElement; + xmlNodeList = xmlElement.ChildNodes; + foreach (XmlNode xmlNode in xmlNodeList) + { + int index = BaselineList.Rows.Add(); + /*string name = xmlNode["name"].InnerText;*/ + BaselineList.Rows[index].Cells[0].Value = xmlNode["name"].InnerText; + BaselineList.Rows[index].Cells[1].Value = xmlNode["description"].InnerText; + BaselineList.Rows[index].Cells[4].Value = xmlNode["standard"].InnerText; + string queryType = xmlNode["type"].InnerText; + string reality; + switch (queryType) { - int index = BaselineList.Rows.Add(); - /*string name = xmlNode["name"].InnerText;*/ - BaselineList.Rows[index].Cells[0].Value = xmlNode["name"].InnerText; - BaselineList.Rows[index].Cells[1].Value = xmlNode["description"].InnerText; - BaselineList.Rows[index].Cells[2].Value = xmlNode["registry"].InnerText; - BaselineList.Rows[index].Cells[3].Value = xmlNode["regitem"].InnerText; - BaselineList.Rows[index].Cells[4].Value = xmlNode["standard"].InnerText; - //检测实际值 - string reality = RegistryHelper.GetValue(Registry.LocalMachine, xmlNode["registry"].InnerText, xmlNode["regitem"].InnerText); - BaselineList.Rows[index].Cells[5].Value = reality; - if (reality == xmlNode["standard"].InnerText) - { - BaselineList.Rows[index].Cells[6].Value = "符合"; - } - BaselineList.Rows[index].Cells[6].Value = "不符合"; + case "secedit": + reality = GetResultByMark(xmlNode["mark"].InnerText); + BaselineList.Rows[index].Cells[5].Value = reality; + break; + case "registry": + BaselineList.Rows[index].Cells[2].Value = xmlNode["registry"].InnerText; + BaselineList.Rows[index].Cells[3].Value = xmlNode["regitem"].InnerText; + reality = RegistryHelper.GetValue(Registry.LocalMachine, xmlNode["registry"].InnerText, xmlNode["regitem"].InnerText); + BaselineList.Rows[index].Cells[5].Value = reality; + break; + default: + break; + } + /*if (reality == xmlNode["standard"].InnerText) + { + BaselineList.Rows[index].Cells[6].Value = "符合"; } + BaselineList.Rows[index].Cells[6].Value = "不符合";*/ } + } } }