Skip to content

Commit

Permalink
分类处理配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
DeEpinGh0st committed Jan 4, 2024
1 parent 16cfad6 commit 164a1b4
Showing 1 changed file with 84 additions and 21 deletions.
105 changes: 84 additions & 21 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public Main()
{
InitializeComponent();
}
string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
XmlNodeList xmlNodeList;
XmlDocument xmlDocument;
XmlElement xmlElement;
Expand All @@ -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");
Expand Down Expand Up @@ -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 = "不符合";*/
}

}
}
}

0 comments on commit 164a1b4

Please sign in to comment.