コード例 #1
0
        /// <summary>
        /// 读取注册信息
        /// </summary>
        /// <returns></returns>
        private static bool readRegisterInfor()
        {
            #region
            RegistryKey regRootKey = Registry.CurrentUser;
            RegistryKey regSubKey;
            try
            {
                regSubKey = regRootKey.OpenSubKey(RegisterInformation.RootNodeRegisterPath);

                _RegisterInfor = new RegisterInformation();
                _RegisterInfor.SerialNumber = regSubKey
                                              .GetValue(RegisterInformation.KeyNameSerialNumber).ToString();

                _RegisterInfor.Username = regSubKey
                                          .GetValue(RegisterInformation.KeyNameUsername).ToString();

                _RegisterInfor.DiskNumber = regSubKey
                                            .GetValue(RegisterInformation.KeyNameDiskNumber).ToString();
                return(true);
            }
            catch (Exception e)
            {
                //预期异常类型应该两种
                //1.没有本公司的注册信息。
                //2.注册信息不全。
                //这两种情况需重新注册
                ErrorInformation = e.ToString();
                return(false);
            }
            #endregion
        }
コード例 #2
0
        /// <summary>
        /// 软件注册开始执行
        /// </summary>
        /// <param name="willreginfor">即将注册的信息</param>
        /// <returns>注册是否成功</returns>
        public static bool Start(RegisterInformation willreginfor)
        {
            #region
            _RegisterInfor = willreginfor;

            if (IsRegisteringValid())
            {
                RegistryKey regRootKey = Registry.CurrentUser;

                RegistryKey regSubKey = regRootKey.CreateSubKey(
                    RegisterInformation.RootNodeRegisterPath, RegistryKeyPermissionCheck.ReadWriteSubTree);

                regSubKey.SetValue(RegisterInformation.KeyNameSerialNumber, _RegisterInfor.SerialNumber,
                                   RegistryValueKind.String);

                regSubKey.SetValue(RegisterInformation.KeyNameUsername, _RegisterInfor.Username,
                                   RegistryValueKind.String);

                regSubKey.SetValue(RegisterInformation.KeyNameDiskNumber, _RegisterInfor.DiskNumber,
                                   RegistryValueKind.String);

                regRootKey.Close();
                return(true);
            }
            return(false);

            #endregion
        }