一般用在域环境下,读取客户机注册的配制信息. private void button1_Click(object sender, System.EventArgs e) ThreadStart threadDelegate = new ThreadStart(this.doIt); WaitCallback async = new WaitCallback(RunGet); //RunGet(remoteName); private void RunGet(object ip) // Print the values. // Close the registry key. } private void button2_Click(object sender, System.EventArgs e) private void button3_Click(object sender, System.EventArgs e)
主要代码如下:
{
tabControl1.SelectedIndex=1;
Thread newThread = new Thread(threadDelegate);
newThread.Start();
}
private int number = 0;
private void doIt()
{
int maxthread = int.Parse(txt_numThread.Text);
string remoteName;
progressBar1.Value = 0;
progressBar1.Maximum =(int)n_ip2.Value-(int)n_ip1.Value;
for(Decimal i = n_ip1.Value;i<=n_ip2.Value;i++)
{
remoteName = txt_ipStart.Text+”.”+i.ToString();
while(true)
{
Monitor.Enter(number);
if(number>5)
Thread.Sleep(1000);
else
break;
Monitor.Exit(number);
}
if(ThreadPool.QueueUserWorkItem(async,remoteName))
Interlocked.Increment(ref number);
}
while(true)
{
//myResetEvent.Set();
Monitor.Enter(number);
if( number <= 0)
break;
else
Thread.Sleep(1000);
Monitor.Exit(number);
}
MessageBox.Show(“完成”);
}
{
try
{
RegistryKey environmentKey = null;
string remoteName = ip.ToString();
try
{
// Open HKEY_CURRENT_USER\Environment
// on a remote computer.
environmentKey = RegistryKey.OpenRemoteBaseKey(
RegistryHive.LocalMachine, remoteName).OpenSubKey(
txt_key.Text);
}
catch(IOException ex)
{
addMsg(string.Format(“{0}: {1}”, remoteName, ex.Message));
}
// MessageBox.Show(string.Format(“\nThere are {0} values for {1}.”,
// environmentKey.ValueCount.ToString(),
// environmentKey.Name));
//addMsg(environmentKey.GetValue(“AutoAdminLogon”).ToString());
object result = environmentKey.GetValue(txt_value.Text);
if(result != null)
{
addMsg(string.Format(“{0}\t\t{1}”,remoteName,result));
addSuccessMsg(remoteName,result.ToString());
}
else
{
addMsg(string.Format(“{0}\t\t读取失败”,remoteName));
}
// foreach(string valueName in environmentKey.GetValueNames())
// {
// addMsg(string.Format(“{0,-20}: {1}”, valueName, environmentKey.GetValue(valueName).ToString()));
// }
environmentKey.Close();
}
catch
{
}
progressBar1.PerformStep();
Interlocked.Decrement(ref number);
private void addMsg(string msg)
{
lb_msg.Items.Insert(0,msg);
}
private void addSuccessMsg(string Ip,string value)
{
txt_result.Text = string.Format(“{0}\t\t{1}\r\n”,Ip,value)+txt_result.Text;
}
{
lb_msg.Items.Clear();
}
{
System.IO.StreamWriter sw = new StreamWriter(“C:\\1.txt”,false,System.Text.Encoding.Default);
sw.Write(txt_result.Text);
sw.Close();
MessageBox.Show(“保存到C:\\1.txt”);
}
http://www.cnblogs.com/edobnet/archive/2006/11/24/571383.html
远程注册表读取,与多线程池的应用_c#应用
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 远程注册表读取,与多线程池的应用_c#应用
相关推荐
-      利用c#远程存取access数据库_c#应用
-      c# 3.0新特性系列:隐含类型var_c#教程
-      c#动态生成树型结构的web程序设计_c#应用
-      论c#变得越来越臃肿是不可避免的_c#应用
-      用c#监控并显示cpu状态信息_c#应用
-      c#中实现vb中的createobject方法_c#应用
-      photoshop给花瓶打造彩绘效果_photoshop教程
-      使用c#创建sql server的存储过程_c#应用