Skip to content

Commit

Permalink
完成大致框架
Browse files Browse the repository at this point in the history
  • Loading branch information
DeEpinGh0st committed Jan 5, 2024
1 parent 164a1b4 commit 8a296a8
Show file tree
Hide file tree
Showing 7 changed files with 470 additions and 43 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,6 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

![Dd]ebug/config.cfg
4 changes: 2 additions & 2 deletions Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 102 additions & 37 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using WHC.OrderWater.Commons;
using System.IO;
using System.Reflection;
using System.Windows.Forms.VisualStyles;
using System.Threading;

namespace WindowsBaselineAssistant
{
Expand All @@ -37,52 +39,66 @@ private XmlDocument ReadXml(string xmlpath) {
}

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

IniFile ini = new IniFile(currentDirectory + "\\config.cfg");
string[] sections = ini.Sections;
string name = string.Empty;
foreach (var section in sections)
{
// 启动进程
process.Start();
// 获取命令输出
string output = process.StandardOutput.ReadToEnd().Split("=")[1];
// 等待进程执行完成
process.WaitForExit();
// 打印输出结果
return output;
name = ini.ReadString(section, mark, "");
if (name != string.Empty)
{
break;
}
}
catch (Exception ex)
{
UIMessageBox.ShowError(ex.Message);
return null;
return name;
}


private int GenerateSecInfo() {
//要执行的命令
string command = "secedit /export /cfg config.cfg";
// 创建一个新的进程启动信息
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
Arguments = "/c " + command,
WorkingDirectory = currentDirectory
};
// 创建进程对象
Process process = new Process
{
StartInfo = processStartInfo
};
try
{
// 启动进程
process.Start();
process.WaitForExit();
Thread.Sleep(1000);
// 获取返回值
int exitCode = process.ExitCode;
return exitCode;
}
catch (Exception ex)
{
UIMessageBox.ShowError(ex.Message);
return -1;
}
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 @@ -118,6 +134,12 @@ private void CheckBtn_Click(object sender, EventArgs e)
UIMessageBox.ShowError("未找到配置文件");
return;
}
//int code = GenerateSecInfo();
if (!GenerateSecInfo().Equals(0))
{
UIMessageBox.ShowError("secedit信息生成失败");
return;
}
BaselineList.Rows.Clear();
xmlElement = xmlDocument.DocumentElement;
xmlNodeList = xmlElement.ChildNodes;
Expand All @@ -129,10 +151,13 @@ private void CheckBtn_Click(object sender, EventArgs e)
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;
string reality = string.Empty;
string standard = xmlNode["standard"].InnerText;
switch (queryType)
{
case "secedit":
BaselineList.Rows[index].Cells[2].Value = "-";
BaselineList.Rows[index].Cells[3].Value = "-";
reality = GetResultByMark(xmlNode["mark"].InnerText);
BaselineList.Rows[index].Cells[5].Value = reality;
break;
Expand All @@ -145,6 +170,46 @@ private void CheckBtn_Click(object sender, EventArgs e)
default:
break;
}
string dataType = xmlNode["dtype"].InnerText;
BaselineList.Rows[index].Cells[6].Value = "不符合";
switch (dataType)
{
case "fixed":
if (!reality.Equals(standard))
{
BaselineList.Rows[index].Cells[6].Value = "符合";
}
break;
case "equals":
case "enum":
if (reality.Equals(standard))
{
BaselineList.Rows[index].Cells[6].Value = "符合";
}
break;
case "greaternumber":

if (reality.ToInt() >= standard.ToInt())
{
BaselineList.Rows[index].Cells[6].Value = "符合";
}
break;
case "lessnumber":
if (reality.ToInt() <= standard.ToInt())
{
BaselineList.Rows[index].Cells[6].Value = "符合";
}
break;
case "array":
if (reality.Equals(standard))
{
BaselineList.Rows[index].Cells[6].Value = "符合";
}
break;
default:
BaselineList.Rows[index].Cells[6].Value = "未定义的类型";
break;
}
/*if (reality == xmlNode["standard"].InnerText)
{
BaselineList.Rows[index].Cells[6].Value = "符合";
Expand Down
73 changes: 73 additions & 0 deletions Properties/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC 清单选项
如果想要更改 Windows 用户帐户控制级别,请使用
以下节点之一替换 requestedExecutionLevel 节点。
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
如果你的应用程序需要此虚拟化来实现向后兼容性,则移除此
元素。
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
Windows 版本的列表。取消评论适当的元素,
Windows 将自动选择最兼容的环境。 -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- 指示该应用程序可感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
选择加入。选择加入此设置的 Windows 窗体应用程序(面向 .NET Framework 4.6)还应
在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。
将应用程序设为感知长路径。请参阅 https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
-->
<!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>
26 changes: 23 additions & 3 deletions RegistryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public sealed class RegistryHelper
/// </summary>
/// <param name="key">registry key</param>
/// <returns>Returns the value of the specified key.</returns>
///
private static string ArrayToString(string[] strings) {
string result = string.Empty;
foreach (var item in strings)
{
result = result + item + "\r\n";
}
return result;
}

public static string GetValue(string key)
{
return GetValue(Registry.CurrentUser,Software_Key, key);
Expand All @@ -43,12 +53,22 @@ public static string GetValue(RegistryKey registryKey, string softwareKey, strin
int indexOfFirstBackslash = softwareKey.IndexOf('\\');
softwareKey = softwareKey.Substring(indexOfFirstBackslash + 1);
RegistryKey regKey = registryKey.OpenSubKey(softwareKey);
if (regKey.GetValue(key) == null) {
object value = regKey.GetValue(key);
if (value == null) {
return "未设置";
}
if (regKey.GetValueKind(key) == RegistryValueKind.MultiString && regKey.GetValue(key) is string[] stringArray && (stringArray == null || stringArray.Length == 0)) {
return "";
if (value is string[] stringArray)
{
if (stringArray.Length.Equals(0))
{
return "";
}
strRet = ArrayToString((string[])value);
return strRet;
}
/*if (regKey.GetValueKind(key) == RegistryValueKind.MultiString && regKey.GetValue(key) is string[] stringArray && (stringArray == null || stringArray.Length == 0)) {
return "";
}*/
strRet = regKey.GetValue(key).ToString();
}
catch
Expand Down
32 changes: 32 additions & 0 deletions WindowsBaselineAssistant.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -35,6 +50,15 @@
<PropertyGroup>
<StartupObject>WindowsBaselineAssistant.Program</StartupObject>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Compile Include="Main.cs">
<SubType>Form</SubType>
Expand Down Expand Up @@ -69,6 +93,14 @@
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\app.manifest" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit 8a296a8

Please sign in to comment.