检查系统设置的工具 [英] Tool which checks the system settings

查看:78
本文介绍了检查系统设置的工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所需软件:
-需要一个工具来检查PC上的设置是否正确.
-如果设置不正确,则该工具需要:
更正设置
写日志条目
显示用户的消息框
-必须检查的设置需要在XML文件中进行配置(设置项)
-具有这些设置项的XML文件需要使用图形编辑器进行编辑,该图形编辑器也应作为此工具的一部分
-要创建带有标准设置(即网络设置)的设置项目模板,需要在另一个XML文件中提供
-通过使用命令行参数,检查器和编辑器应可分别启动
___________________________________________________________________________

下面是我的代码,实际上我被分配来设计一个小型应用程序,该应用程序必须检查系统设置(注册表文件,ini文件等),并为这些注册表设置生成xml程序.该程序应包含两个不同的类,一个用于检查注册表文件,并且应在禁用模式下运行,如果xml和注册表之间缺少匹配项,则应生成一个日志文件并应启用该表单.另一个类用于编辑,如果有错误,则应启用申请表.

使用Microsoft.Win32;
使用System.Xml;

命名空间ReadRegistrySettings
{
公共局部类Form1:Form
{
公共Form1()
{
InitializeComponent();
}

私有void Form1_Load(对象发送者,EventArgs e)
{
字符串myHost = System.Net.Dns.GetHostName(); //获取主机名
MessageBox.Show(主机名:\ t" + myHost); //显示主机名
字符串myIP = System.Net.Dns.GetHostByName(myHost).AddressList [0] .ToString();//从主机名获取IP
MessageBox.Show("IP:\ t" + myIP);//显示IP
TestChecker TCheck =新的TestChecker();
XmlDocument xdoc =新的XmlDocument();
xdoc.Load(@"D:\\ VSTS2010solutions \\ Test_config_profile \\ Test_config_profile \\ Config_OutputProfileManager.xml");
TCheck.GetDatabaseConnectionString();
ReadRegistry();

}
私有void ReadRegistry()
{
//HKEY_CLASSES_ROOT
TreeNode rootNode =新的TreeNode(Registry.ClassesRoot.Name,0,1);
string [] rootSubKeys = Registry.ClassesRoot.GetSubKeyNames();
foreach(rootSubKeys中的字符串键)
{
TreeNode节点=新的TreeNode(key,0,1);
string [] subKeys = Registry.ClassesRoot.OpenSubKey(key).GetSubKeyNames();
foreach(subKeys中的字符串subKeysKey)
{
node.Nodes.Add(subKeysKey,subKeysKey,0、1);
}

rootNode.Nodes.Add(node);
}
RegistryTreeView.Nodes.Add(rootNode);

//HKEY_CURRENT_CONFIG
TreeNode configNode = new TreeNode(Registry.CurrentConfig.Name,0,1);
字符串[] configSubKeys = Registry.CurrentConfig.GetSubKeyNames();
foreach(configSubKeys中的字符串键)
{
TreeNode节点=新的TreeNode(key,0,1);
string [] subKeys =
Registry.CurrentConfig.OpenSubKey(key).GetSubKeyNames();
foreach(subKeys中的字符串subKeysKey)
node.Nodes.Add(subKeysKey,subKeysKey,0、1);

configNode.Nodes.Add(node);
}
RegistryTreeView.Nodes.Add(configNode);

//HKEY_CURRENT_USER
TreeNode currentUserNode =新的TreeNode(Registry.CurrentUser.Name,0,1);
string [] currentUserSubKeys = Registry.CurrentUser.GetSubKeyNames();
foreach(currentUserSubKeys中的字符串键)
{
TreeNode节点=新的TreeNode(key,0,1);
string []子键= Registry.CurrentUser.OpenSubKey(key).GetSubKeyNames();
foreach(subKeys中的字符串subKeysKey)
node.Nodes.Add(subKeysKey,subKeysKey,0、1);

currentUserNode.Nodes.Add(node);
}
RegistryTreeView.Nodes.Add(currentUserNode);

//HKEY_LOCAL_MACHINE
TreeNode localMachineNode =新的TreeNode(Registry.LocalMachine.Name);
string [] localMachineSubKeys = Registry.LocalMachine.GetSubKeyNames();
foreach(localMachineSubKeys中的字符串键)
{
TreeNode节点=新的TreeNode(key,0,1);

试试
{
string [] subKeys =
Registry.LocalMachine.OpenSubKey(key,false).GetSubKeyNames();
foreach(subKeys中的字符串subKeysKey)
node.Nodes.Add(subKeysKey,subKeysKey,0、1);
}
catch(Exception)
{
//如果用户无权访问此子项,则会引发异常
//如果是这种情况,请更改图标以显示暗淡的文件夹
node.ImageIndex = 4;
node.SelectedImageIndex = 5;
}

localMachineNode.Nodes.Add(node);
}
RegistryTreeView.Nodes.Add(localMachineNode);

//HKEY_USERS
TreeNode usersNode =新的TreeNode(Registry.Users.Name);
string [] usersSubKeys = Registry.Users.GetSubKeyNames();
foreach(usersSubKeys中的字符串键)
{
TreeNode节点=新的TreeNode(key,0,1);

试试
{
string [] subKeys = Registry.Users.OpenSubKey(key).GetSubKeyNames();
foreach(subKeys中的字符串subKeysKey)
node.Nodes.Add(subKeysKey,subKeysKey,0、1);
}
catch(Exception)
{
//如果用户无权访问此子项,则会引发异常
//如果是这种情况,请更改图标以显示暗淡的文件夹
node.ImageIndex = 4;
node.SelectedImageIndex = 5;
}

usersNode.Nodes.Add(node);
}
RegistryTreeView.Nodes.Add(usersNode);
}

私有静态无效GetValuesAndData(RegistryKey RegistryKey,TreeNode节点)
{
字符串[]值= RegistryKey.GetValueNames();
foreach(值中的字符串值)
{
对象数据= RegistryKey.GetValue(value);

if(数据!= null)
{
字符串stringData = data.ToString();

//如果数据太长,则仅显示开头
如果(stringData.Length> 50)
stringData = stringData.Substring(0,46)+"...";

//显示值的数据.条件运算符是
//需要,因为默认值没有名称
node.Nodes.Add(值,(值=="?默认":值)+
:" + stringData,2,2);
}
其他
{
//显示< empty>如果值为空
node.Nodes.Add(值,(值=="?默认":值)+
:< empty>",2,2);
}
}
}
private void button1_Click(对象发送者,EventArgs e)
{
RegistryKey rkey = Registry.LocalMachine;
RegistryKey rkeySoftware = rkey.OpenSubKey("SOFTWARE");
RegistryKey rkeyVendor = rkeySoftware.OpenSubKey("ambatiREG_File");
RegistryKey rkeyVersions = rkeyVendor.OpenSubKey(连接参数列表");

String [] ValueNames = rkeyVersions.GetValueNames();
foreach(ValueNames中的字符串名称)
{
MessageBox.Show(name +:" + rkeyVersions.GetValue(name).ToString());
}

Log_Checker Log2 =新的Log_Checker();
Log2.Checker("SOFTWARE","ambatiREG_File",连接参数列表");

RegChecker Rchk =新的RegChecker();
Rchk.checkMachineType();
}
私有void Writing_Click(对象发送者,EventArgs e)
{
RegistryKey ParentKey = Registry.LocalMachine;
RegistryKey软件密钥= ParentKey.OpenSubKey("Software",true);
RegistryKey子项= softwarekey.CreateSubKey("ambatiREG_File");
MessageBox.Show("Writing Code");
subkey.SetValue("Name",",RegistryValueKind.String);
subkey.SetValue("MyWebsitePrimary",",RegistryValueKind.String);
subkey.SetValue("IPAddress","172.00.12.23",RegistryValueKind.String);
RegistryKey的文章SubKey = subkey.CreateSubKey(连接参数列表");
ArticlesSubKey.SetValue("LAN卡","LAN卡");
ArticlesSubKey.SetValue("Bluetooth","Bluetooth card");
ArticlesSubKey.SetValue(打印机连接",打印机卡");
ArticlesSubKey.SetValue("Scanners","Scanner Card");

日志log1 =新的Log();
log1.Check("x","y","172.00.12.23");

//subkey.DeleteValue("IPAddress");

}
}
}

此代码用于读取注册表文件并在树视图列表中显示.
请帮帮我.

Requested Software:
- need a tool which checks if the settings made on a PC are correct.
- In case the settings are not correct the tool needs to:
Correct the settings
Write log entries
Show message box for the user
- The settings which have to be checked need to be configurable in an XML file (settings items)
- The XML file with those settings items need to be editable with a graphical editor which should be also part of this tool
- For creation of the settings items templates with standard settings (i.e. network settings) need to be provided in another XML file
- The checker and the editors should be startable separately by using command line parameters
___________________________________________________________________________

The below is my code, actually i been assigned to design a small application which have to check the system settings (registry files, ini files etc)and to generate an xml program for those registry settings. the program should consists of two different classes one is for checking the registry files and it should run in disable mode, if there is a miss match between the xml and registry then it should generate a log file and it should enable the form. the other class is for editing if there is an error then the application form should enable.

using Microsoft.Win32;
using System.Xml;

namespace ReadRegistrySettings
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string myHost = System.Net.Dns.GetHostName(); // Get the hostname
MessageBox.Show("Host Name:\t" + myHost); // Show the hostname
string myIP = System.Net.Dns.GetHostByName(myHost).AddressList[0].ToString();// Get the IP from the host name
MessageBox.Show("IP:\t"+myIP);// Show the IP
TestChecker TCheck = new TestChecker();
XmlDocument xdoc = new XmlDocument();
xdoc.Load(@"D:\\VSTS2010solutions\\Test_config_profile\\Test_config_profile\\Config_OutputProfileManager.xml");
TCheck.GetDatabaseConnectionString();
ReadRegistry();

}
private void ReadRegistry()
{
//HKEY_CLASSES_ROOT
TreeNode rootNode = new TreeNode(Registry.ClassesRoot.Name, 0, 1);
string[] rootSubKeys = Registry.ClassesRoot.GetSubKeyNames();
foreach (string key in rootSubKeys)
{
TreeNode node = new TreeNode(key, 0, 1);
string[] subKeys = Registry.ClassesRoot.OpenSubKey(key).GetSubKeyNames();
foreach (string subKeysKey in subKeys)
{
node.Nodes.Add(subKeysKey, subKeysKey, 0, 1);
}

rootNode.Nodes.Add(node);
}
registryTreeView.Nodes.Add(rootNode);

//HKEY_CURRENT_CONFIG
TreeNode configNode = new TreeNode(Registry.CurrentConfig.Name, 0, 1);
string[] configSubKeys = Registry.CurrentConfig.GetSubKeyNames();
foreach (string key in configSubKeys)
{
TreeNode node = new TreeNode(key, 0, 1);
string[] subKeys =
Registry.CurrentConfig.OpenSubKey(key).GetSubKeyNames();
foreach (string subKeysKey in subKeys)
node.Nodes.Add(subKeysKey, subKeysKey, 0, 1);

configNode.Nodes.Add(node);
}
registryTreeView.Nodes.Add(configNode);

//HKEY_CURRENT_USER
TreeNode currentUserNode = new TreeNode(Registry.CurrentUser.Name, 0, 1);
string[] currentUserSubKeys = Registry.CurrentUser.GetSubKeyNames();
foreach (string key in currentUserSubKeys)
{
TreeNode node = new TreeNode(key, 0, 1);
string[] subKeys = Registry.CurrentUser.OpenSubKey(key).GetSubKeyNames();
foreach (string subKeysKey in subKeys)
node.Nodes.Add(subKeysKey, subKeysKey, 0, 1);

currentUserNode.Nodes.Add(node);
}
registryTreeView.Nodes.Add(currentUserNode);

//HKEY_LOCAL_MACHINE
TreeNode localMachineNode = new TreeNode(Registry.LocalMachine.Name);
string[] localMachineSubKeys = Registry.LocalMachine.GetSubKeyNames();
foreach (string key in localMachineSubKeys)
{
TreeNode node = new TreeNode(key, 0, 1);

try
{
string[] subKeys =
Registry.LocalMachine.OpenSubKey(key, false).GetSubKeyNames();
foreach (string subKeysKey in subKeys)
node.Nodes.Add(subKeysKey, subKeysKey, 0, 1);
}
catch (Exception)
{
//an exception is thrown if the user has no access to this subkey
//if this is the case, change the icon to show a dimmed folder
node.ImageIndex = 4;
node.SelectedImageIndex = 5;
}

localMachineNode.Nodes.Add(node);
}
registryTreeView.Nodes.Add(localMachineNode);

//HKEY_USERS
TreeNode usersNode = new TreeNode(Registry.Users.Name);
string[] usersSubKeys = Registry.Users.GetSubKeyNames();
foreach (string key in usersSubKeys)
{
TreeNode node = new TreeNode(key, 0, 1);

try
{
string[] subKeys = Registry.Users.OpenSubKey(key).GetSubKeyNames();
foreach (string subKeysKey in subKeys)
node.Nodes.Add(subKeysKey, subKeysKey, 0, 1);
}
catch (Exception)
{
//an exception is thrown if the user has no access to this subkey
//if this is the case, change the icon to show a dimmed folder
node.ImageIndex = 4;
node.SelectedImageIndex = 5;
}

usersNode.Nodes.Add(node);
}
registryTreeView.Nodes.Add(usersNode);
}

private static void GetValuesAndData(RegistryKey registryKey, TreeNode node)
{
string[] values = registryKey.GetValueNames();
foreach (string value in values)
{
object data = registryKey.GetValue(value);

if (data != null)
{
string stringData = data.ToString();

//if the data is too long, display the begining only
if (stringData.Length > 50)
stringData = stringData.Substring(0, 46) + " ...";

//Display the data of the value. The conditional operatore is
//needed because the default value has no name
node.Nodes.Add(value, (value == "" ? "Default" : value) +
": " + stringData, 2, 2);
}
else
{
//Display <empty> if the value is empty
node.Nodes.Add(value, (value == "" ? "Default" : value) +
": <empty>", 2, 2);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
RegistryKey rkey = Registry.LocalMachine;
RegistryKey rkeySoftware = rkey.OpenSubKey("SOFTWARE");
RegistryKey rkeyVendor = rkeySoftware.OpenSubKey("ambatiREG_File");
RegistryKey rkeyVersions = rkeyVendor.OpenSubKey("List of Connected Parameters");

String[] ValueNames = rkeyVersions.GetValueNames();
foreach (string name in ValueNames)
{
MessageBox.Show(name + ": " + rkeyVersions.GetValue(name).ToString());
}

Log_Checker Log2 = new Log_Checker();
Log2.Checker("SOFTWARE", "ambatiREG_File", "List of Connected Parameters");

RegChecker Rchk = new RegChecker();
Rchk.checkMachineType();
}
private void Writing_Click(object sender, EventArgs e)
{
RegistryKey ParentKey = Registry.LocalMachine;
RegistryKey softwarekey = ParentKey.OpenSubKey("Software", true);
RegistryKey subkey = softwarekey.CreateSubKey("ambatiREG_File");
MessageBox.Show("Writing Code");
subkey.SetValue("Name", " ", RegistryValueKind.String);
subkey.SetValue("MyWebsitePrimary", " ", RegistryValueKind.String);
subkey.SetValue("IPAddress", "172.00.12.23", RegistryValueKind.String);
RegistryKey articlesSubKey = subkey.CreateSubKey("List of Connected Parameters");
articlesSubKey.SetValue("LAN Card", "LAN Card");
articlesSubKey.SetValue("Bluetooth", "Bluetooth card");
articlesSubKey.SetValue("Printer Connections", "Printer card");
articlesSubKey.SetValue("Scanners", "Scanner Card");

Log log1 = new Log();
log1.Check("x", "y", "172.00.12.23");

// subkey.DeleteValue("IPAddress");

}
}
}

this code is for reading the registry files and displaying in a tree view list.
please help me out.

推荐答案

这是转发.有人告诉您,这不是这里的工作方式.目前,这只是一项家庭作业声明.

再一次,这是询问者的期望:
1. 先尝试您要做什么!
2.制定看起来像问题/无法解决的问题.

试试看,告诉他们是否遇到问题.
成员将很乐意为您提供帮助.
This is a repost. You were told that this is not the way how things works here. For now, it is just a homework statement.

Once again, here is what is expected of enquirers:
1. TRY first what you want to do!
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.


这篇关于检查系统设置的工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆