using System.Security.Cryptography;pregkey = Registry.CurrentUser.OpenSubKey("Software\\wmaple_mail", true);            if (pregkey == null)
            {
                RegistryKey pregkey1 = Registry.CurrentUser.CreateSubKey("Software\\wmaple_mail");
            }我在程序中用到了注册表存值功能,在我本机测试倒是没有问题,可以用到别的机子上就不行了,别的机子上.net框架没问题,只要我把这块注册表的程序删掉就可以打开,
没有删掉,xp是关闭,03就没有反应,很奇怪,

解决方案 »

  1.   

    try{}catch{}捕获异常,看看是什么异常,另外注册表键值是否一定存在。
      

  2.   

    if (pregkey == null) 
                { 
                    RegistryKey pregkey1 = Registry.CurrentUser.CreateSubKey("Software\\wmaple_mail"); 
                } 加一个Close试试。
    if (pregkey == null) 
                { 
                    RegistryKey pregkey1 = Registry.CurrentUser.CreateSubKey("Software\\wmaple_mail"); 
                    pregkey1.Close();
                } 
      

  3.   

    加一个Close试试。 
    if (pregkey == null) 
                { 
                    RegistryKey pregkey1 = Registry.CurrentUser.CreateSubKey("Software\\wmaple_mail"); 
                    pregkey1.Close(); 
                } 
    不起作用
      

  4.   

    msdn 中 CreateSubKey 函数的文档中例子有这个属性,// 程序集的属性, 那台机器环境的配置问题?
    [assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum,
        ViewAndModify = "HKEY_CURRENT_USER")]
      

  5.   

    用try{}catch{}捕获异常,看看是什么异常,另外注册表键值是否一定存在。
    怎么得到他的异常中,提示什么地方出错了
      

  6.   

    try
       {
        pregkey = Registry.CurrentUser.OpenSubKey("Software\\wmaple_mail"); 
        if (pregkey == null)
         {
            return false;
          }
          return true;
     }
     catch
       {
         return false;
      }
    或通过throw抛出异常