熱點推薦:
您现在的位置: 電腦知識網 >> 操作系統 >> Windows系統管理 >> 正文

遠程注冊表讀取,與多線程池的應用

2022-06-13   來源: Windows系統管理 
一般用在域環境下讀取客戶機注冊的配制信息
主要代碼如下:

  private void button_Click(object sender SystemEventArgs e)
        {
            tabControlSelectedIndex=;

  ThreadStart threadDelegate = new ThreadStart(thisdoIt);
            Thread newThread = new Thread(threadDelegate);
            newThreadStart();

  }
        private int number = ;
        private void doIt()
        {
            int maxthread = intParse(txt_numThreadText);
            string remoteName;
            progressBarValue = ;
            progressBarMaximum =(int)n_ipValue(int)n_ipValue;
            for(Decimal i = n_ipValue;i<=n_ipValue;i++)
            {
                remoteName = txt_ipStartText++iToString();

  WaitCallback async = new WaitCallback(RunGet);
                while(true)
                {
                   
                    MonitorEnter(number);
                    if(number>)
                        ThreadSleep();
                    else
                        break;
                    MonitorExit(number);
                }
                if(ThreadPoolQueueUserWorkItem(asyncremoteName))
                    InterlockedIncrement(ref number);

  //RunGet(remoteName);
            }
            while(true)
            {
                //myResetEventSet();
                MonitorEnter(number);
                if( number <= )
                    break;
                else
                    ThreadSleep();
                MonitorExit(number);
            }
            MessageBoxShow(完成);

        }

  private void RunGet(object ip)
        {
            try
            {
                RegistryKey environmentKey = null;
                string remoteName = ipToString();
                try
                {
                    // Open HKEY_CURRENT_USER\Environment
                    // on a remote computer
                    environmentKey = RegistryKeyOpenRemoteBaseKey(
                        RegistryHiveLocalMachine remoteName)OpenSubKey(
                        txt_keyText);
                }
                catch(IOException ex)
                {
                    addMsg(stringFormat({}: {} remoteName exMessage));
               
                }

  // Print the values
                //            MessageBoxShow(stringFormat(\nThere are {} values for {}
                //                environmentKeyValueCountToString()
                //                environmentKeyName));
                //addMsg(environmentKeyGetValue(AutoAdminLogon)ToString());
                object result =     environmentKeyGetValue(txt_valueText);
                if(result != null)
                {
                    addMsg(stringFormat({}\t\t{}remoteNameresult));
                    addSuccessMsg(remoteNameresultToString());
                }
                else
                {
                    addMsg(stringFormat({}\t\t讀取失敗remoteName));
                }
                //            foreach(string valueName in environmentKeyGetValueNames())
                //            {
                //                addMsg(stringFormat({}: {} valueName environmentKeyGetValue(valueName)ToString()));
                //            }

  // Close the registry key
                environmentKeyClose();
            }
            catch
            {
            }
            progressBarPerformStep();
            InterlockedDecrement(ref number);

  }
        private void addMsg(string msg)
        {
            lb_msgItemsInsert(msg);
        }
        private void addSuccessMsg(string Ipstring value)
        {
            txt_resultText = stringFormat({}\t\t{}\r\nIpvalue)+txt_resultText;
        }

  private void button_Click(object sender SystemEventArgs e)
        {
            lb_msgItemsClear();
        }

  private void button_Click(object sender SystemEventArgs e)
        {
            SystemIOStreamWriter sw = new StreamWriter(C:\\txtfalseSystemTextEncodingDefault);
            swWrite(txt_resultText);
            swClose();
            MessageBoxShow(保存到C:\\txt);
        }  


From:http://tw.wingwit.com/Article/os/xtgl/201311/8971.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.