惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
Engineering at Meta
Engineering at Meta
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
B
Blog RSS Feed
GbyAI
GbyAI
P
Proofpoint News Feed
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
D
Docker
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recorded Future
Recorded Future
美团技术团队
The Register - Security
The Register - Security
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
The Blog of Author Tim Ferriss
博客园 - 司徒正美
量子位
B
Blog
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
A
About on SuperTechFans
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
雷峰网
雷峰网
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
L
LangChain Blog
Latest news
Latest news
S
SegmentFault 最新的问题
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Blog — PlanetScale
Blog — PlanetScale
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cisco Talos Blog
Cisco Talos Blog
F
Full Disclosure
C
Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
W
WeLiveSecurity
T
Tenable Blog
T
Tor Project blog

博客园 - edobnet

phonegap 开发初探 .net C# ADC接口中DES加密算法 阿里软件接口开发基础(淘宝网) C# SQL 2005自动备份文件删除 短信猫与中国移动CMPP2。0收发短信实例 通过OSQL命令执行SQL SERVER批SQL 针对sql 2005优化的高性能分页存储过程 .net framework 2.0以上修改config配制更容易 - edobnet LinQ操作汇总(From CSharpSamples) 使用JAVASCRIPT控制,IFAME的内容,从而使用投票点击等功能 ADSL自动断拨号类 类拟EXCEL表格锁定的功能的实现! - edobnet - 博客园 线程,线程数控制! sql Server 2000 分区视图的运用 利用.Net 线程池提高应用程序性能. google 中国编程大赛测试题,及自己的解答 触发器在增量同步数据的运用. 进程服务编写,与启动停止控制 js异步XMLhttpPost,并带有,等待显示,防正,XMLhttpPost请求时间过来,而使浏览器死掉! - edobnet - 博客园
远程注册表读取,与多线程池的应用.
edobnet · 2006-11-24 · via 博客园 - edobnet

界面如下:

一般用在域环境下,读取客户机注册的配制信息.
主要代码如下:

private void button1_Click(object sender, System.EventArgs e)
        
{
            tabControl1.SelectedIndex
=1;

            ThreadStart threadDelegate 
= new ThreadStart(this.doIt);
            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();

                WaitCallback async 
= new WaitCallback(RunGet);
                
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);

            
//RunGet(remoteName);
            }

            
while(true)
            
{
                
//myResetEvent.Set();
                Monitor.Enter(number);
                
if( number <= 0)
                    
break;
                
else
                    Thread.Sleep(
1000);
                Monitor.Exit(number);
            }

            MessageBox.Show(
"完成");

            
        }


        
private void RunGet(object ip)
        
{
            
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));
                
                }


                
// Print the values.
                
//            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()));
                
//            }

                
// Close the registry key.
                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;
        }


        
private void button2_Click(object sender, System.EventArgs e)
        
{
            lb_msg.Items.Clear();
        }


        
private void button3_Click(object sender, System.EventArgs e)
        
{
            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");
        }