首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

大家帮忙看个C#操作注册表的有关问题

2012-02-16 
大家帮忙看个C#操作注册表的问题我下边这个代码是一个很简单的修改IE9进程数的代码,就是在Software\Micros

大家帮忙看个C#操作注册表的问题
我下边这个代码是一个很简单的修改IE9进程数的代码,就是在Software\Microsoft\Internet Explorer\Main下添加一个TabProcGrowth键值。问题出现在:当我添加了如下代码中的注释部分以后,程序就先输出不存在那部分,直到最后一个才输出存在。。

C# code
using System;using Microsoft.Win32;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace IE进程管理{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void btnChangeIEProcessNum_Click(object sender, EventArgs e)        {            RegistryKey key = Registry.CurrentUser;            RegistryKey ieProcessNum = key.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main", true);            string[] valueName;            valueName = ieProcessNum.GetValueNames();            foreach (string s in valueName)            {                if (s == "TabProcGrowth")                {                                        MessageBox.Show("键值存在", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);                    return;                }                if (s != "TabProcGrowth")//添加这部分后,程序就一直提示键值不存在,直到最后才输出键值存在。                {                    MessageBox.Show("键值不存在,要创建吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);                    return;                }           }        }    }}


[解决办法]
C# code
bool bFound = false;foreach (string s in valueName)            {                if (s == "TabProcGrowth")                {                    bFound = true;                    break;                    }             }if (bFound){// 有}else{// 木有} 

热点排行