Esempio n. 1
0
        public static RegKey Parse(string keyPath, bool writable)
        {
            string[] tokens = keyPath.Split(new char[] { '\\' }, 2);
            Microsoft.Win32.RegistryKey rootKey = RegUtility.ParseRootKey(tokens[0]);
            if (tokens.Length == 1)
            {
                return(new RegKey(rootKey));
            }
            string path = tokens[1];
            string name = keyPath.Substring(keyPath.LastIndexOf('\\') + 1);

            try
            {
                var key = rootKey.OpenSubKey(path, writable);
                if (key == null)
                {
                    return(null);
                }
                return(new RegKey(name, key));
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 2
0
        private bool DeleteEntries()
        {
            bool success = true;

            foreach (ListViewItem item in lstResults.SelectedItems)
            {
                RegSearchMatch match = (RegSearchMatch)item.Tag;
                // if value is not specified
                if (match.Value == "-")
                {
                    if (RegUtility.DeleteKey(match.Key))
                    {
                        item.Remove();
                    }
                    else
                    {
                        success = false;
                    }
                }
                else
                if (RegUtility.DeleteValue(match.Key, match.Value))
                {
                    item.Remove();
                }
                else
                {
                    success = false;
                }
            }
            return(success);
        }
Esempio n. 3
0
        private void AddResultToListView(RegSearchMatch result)
        {
            var item = lstResults.Items.Add(result.Key);

            item.Tag = result;
            item.SubItems.Add(RegUtility.GetRegValueName(result.Value));
            item.SubItems.Add(result.Data);
        }
Esempio n. 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            string strRegNumber = RegUtility.GetRegNumber(reginfo.DiskNumber);

            if (txbYzm.Text.Trim() == "")//判断用户名是否为空
            {
                MessageBox.Show("请输入注册码!", "温馨提示:");
                txbYzm.Focus();
                return;
            }

            //注册码
            string zcm = DBA.Code.DecryptionAll(txbYzm.Text.Trim());


            //防止利用相同注册码重复注册延长使用时间
            if (reginfo.SerialNo == zcm)
            {
                MessageBox.Show("请勿使用相同注册码重复注册", "系统注册", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }


            //增加一个万用注册码
            if (txbYzm.Text.Trim() == @"gGHCJGCFREGDFBBIMEFDTEHEQIHEMBEH\CEH_CHBhIGIaIDERHCBdBIF[DBEcHFFECCI")
            {
                MessageBox.Show("恭喜您,注册成功!您获得了此系统的授权", "系统注册", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                //保存注册信息
                reginfo.WriteSerialNo(zcm);
                this.Close();
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                //zcm.Substring(zcm.Length-10)  注册码生成日期 yyyy-mm-dd
                string strPcNm = zcm.Substring(0, zcm.Length - 20);
                //这里还得加个软件当前年版本和注册码年版本的校验!比如当前2006来个2007的注册码

                if (strRegNumber.Equals(strPcNm))
                {
                    //保存注册信息
                    Lib.reginfo.WriteSerialNo(zcm);
                    Lib.reginfo.ReadRegInfo();

                    MessageBox.Show("恭喜您,注册成功!", "系统注册", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    this.Close();
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("请确认您的输入是否正确!", "注册失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Esempio n. 5
0
        private void OnNewValueAction(RegistryValueKind valueKind)
        {
            if (tvwKeys.SelectedNode == null)
            {
                return;
            }
            RegistryKey  key  = (RegistryKey)tvwKeys.SelectedNode.Tag;
            string       name = RegUtility.GetNewValueName(key);
            ListViewItem item = AddValueToList(key, new RegValue(name, valueKind, valueKind.GetDefaultData()));

            lstValues.LabelEdit = true;
            item.BeginEdit();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(RegUtility.GetCpuNumber());

                RegLib.reginfo reg = new RegLib.reginfo();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Esempio n. 7
0
 private void DeleteTreeKey()
 {
     if (UIUtility.ConfirmAction(this, Properties.Resources.Confirm_DeleteKey, "Key Delete", true))
     {
         if (RegUtility.DeleteKey(tvwKeys.SelectedNode.Tag.ToString()))
         {
             tvwKeys.SelectedNode.Remove();
         }
         else
         {
             UIUtility.WarnUser(this, Properties.Resources.Error_DeleteKeyFail);
         }
     }
 }
Esempio n. 8
0
        private void btnFind_Click(object sender, EventArgs e)
        {
            if (btnFind.Text == "F&ind")
            {
                RegistryKey[] keys;

                if (cmbSearch.Text == "All Hives")
                {
                    keys = new RegistryKey[cmbSearch.Items.Count];
                    for (int i = 0; i < cmbSearch.Items.Count; i++)
                    {
                        keys[i] = RegUtility.ParseRootKey(cmbSearch.Items[i].ToString());
                    }
                }
                else
                {
                    keys = new RegistryKey[] { RegUtility.ParseRootKey(cmbSearch.Text) }
                };

                if (txtBranch.Text != String.Empty)
                {
                    keys[0] = keys[0].OpenSubKey(txtBranch.Text);
                    if (keys[0] == null)
                    {
                        UIUtility.DisplayError(this, Properties.Resources.Error_InvalidKey, txtBranch);
                        return;
                    }
                }

                RegSearchArgs searchArgs = GetSearchArgs(keys);
                StartSearch();
                try
                {
                    searcher.Start(searchArgs);
                }
                catch (ArgumentException ex)
                {
                    toolStripStatusLabel1.Text = "Ready.";
                    UIUtility.DisplayError(this, ex.Message, txtPattern);
                    EnableSearch();
                    return;
                }
                searchStarted = true;
            }
            else
            {
                btnFind.Enabled = false;
                searcher.Stop();
            }
        }
Esempio n. 9
0
 /// <summary>
 /// 判断是否注册
 /// </summary>
 /// <returns></returns>
 public bool CheckRegedit(DateTime dtWebHost, bool bIsWebHost)
 {
     try
     {
         string regCode = RegUtility.GetRegNumber(_DiskNumber);
         //if (_SerialNo == "I173387EFIE8" || (!String.IsNullOrEmpty(regCode) && _SerialNo.Equals(regCode)))
         //改为校验前面的硬件ID注册码以及配置年和注册码取出来的年部分(避免买了一年的多IPC版本,把注册码复制到多年用)
         if (_SerialNo == "I1733817EEIE8JFF0")
         {
             return(true);
         }
         else if ((!String.IsNullOrEmpty(regCode) && StrPC_SQM.Equals(regCode)))
         {
             bool bRs = true;
             if (bIsWebHost)
             {
                 bRs = dtWebHost < DtSqEndDate ? true : false;
             }
             else
             {
                 //防止调整客户端时间,造成一直不过期的现象,要求重新注册
                 if (!(DateTime.Now >= _LastUsedTime && _LastUsedTime > _FirstUsedTime))
                 {
                     #region 采取策略是强制过期还是保留使用时间差?
                     ////使用强制过期,不满年直接变为满年
                     //TimeSpan ts = (_LastUsedTime - _FirstUsedTime).Duration();
                     //_FirstUsedTime = DateTime.Now.AddDays(-(ts.Days / nRegDay + 1) * nRegDay);
                     //_LastUsedTime = DateTime.Now;
                     bRs = false;
                     #endregion
                 }
                 else
                 {
                     bRs = DateTime.Now < DtSqEndDate ? true : false;
                 }
             }
             return(bRs);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Esempio n. 10
0
        private bool DeleteValues()
        {
            bool success = true;

            foreach (ListViewItem item in lstValues.SelectedItems)
            {
                if (RegUtility.DeleteValue(item.Tag.ToString(), item.Text))
                {
                    item.Remove();
                }
                else
                {
                    success = false;
                }
            }
            return(success);
        }
Esempio n. 11
0
        private void OnFindAction()
        {
            string key = GetSelectedKey();

            if (key != String.Empty)
            {
                string hive;
                string branch;
                RegUtility.SplitKey(key, out hive, out branch);

                if (!searcher.IsBusy)
                {
                    cmbSearch.SelectedItem = hive;
                    txtBranch.Text         = branch;
                }
            }
            tabControl1.SelectedTab = tbSearch;
            txtPattern.Focus();
        }
Esempio n. 12
0
 private void lstResults_DoubleClick(object sender, EventArgs e)
 {
     if (lstResults.SelectedItems.Count == 1)
     {
         RegSearchMatch match = lstResults.SelectedItems[0].Tag as RegSearchMatch;
         if (JumpToKey(match.Key))
         {
             if (match.Value != "-")
             {
                 string       valueName = RegUtility.GetRegValueName(match.Value);
                 ListViewItem item      = lstValues.Items[valueName];
                 if (item != null)
                 {
                     item.Selected = true;
                     lstValues.Focus();
                 }
             }
         }
     }
 }
Esempio n. 13
0
        private void OnNewKeyAction()
        {
            if (tvwKeys.SelectedNode == null)
            {
                return;
            }
            if (tvwKeys.HasChildren && !tvwKeys.SelectedNode.IsExpanded)
            {
                tvwKeys.SelectedNode.Expand();
            }
            RegistryKey key  = (RegistryKey)tvwKeys.SelectedNode.Tag;
            string      name = RegUtility.GetNewKeyName(key);
            string      path = key.Name + "\\" + name;
            // adding new object() as tag to prevent this key from being deleted on expanding.
            TreeNode node = CreateNode(path, name, new object());

            tvwKeys.SelectedNode.Nodes.Add(node);
            node.EnsureVisible();
            tvwKeys.LabelEdit = true;
            node.BeginEdit();
        }
        public async Task <RESTResult> AddOrUpdateUserAsync(Guid currentUserId, Guid id, bool isAdd, RegisterUserDto input)
        {
            RESTResult result = new RESTResult {
                Code = RESTStatus.Failed
            };

            if (!RegUtility.IsValidationForEmail(input.AccountEmail))
            {
                throw new ArgumentException("Wrong Email format!");
            }
            if (!string.IsNullOrEmpty(input.AccountPhone) && !RegUtility.IsValidationForPhone(input.AccountPhone))
            {
                throw new ArgumentException("Wrong Phone format!");
            }
            if (isAdd)
            {
                //Check the user whteher exist in User
                var userEntities = await _userRepository.GetAllListAsync(item => item.AccountEmail.Equals(input.AccountEmail) || item.AccountCode.Equals(input.AccountCode) || item.AccountPhone.Equals(input.AccountPhone));

                if (userEntities.Count > 0)
                {
                    throw new ArgumentException($"The user {input.AccountEmail} {input.AccountCode} {input.AccountEmail} have been exist");
                }
                var userEntity = new User();
                userEntity.Id           = Guid.NewGuid();
                userEntity.AccountEmail = input.AccountEmail;
                userEntity.AccountPhone = input.AccountPhone;
                userEntity.AccountCode  = input.AccountCode;
                //It need to be optimized.
                userEntity.LastLoginIP   = "127.0.0.1";
                userEntity.CreateTime    = DateTime.Now;
                userEntity.LastLoginTime = DateTime.Now;
                userEntity.Password      = HashUtility.CreateHash(string.IsNullOrEmpty(input.Password) ? GeneralPassword(input.AccountEmail) : input.Password);
                await _userRepository.InsertAsync(userEntity);

                if (input.UserInfo != null)
                {
                    var userInfoEntity = Mapper.Map <UserInfoDto, UserInfo>(input.UserInfo);
                    await _userInfoRepository.InsertAsync(userInfoEntity);
                }
                await SetUserAndDepartmentMapAsync(currentUserId, userEntity.Id, input.DepartmentId);
                await SetUserAndRoleMapAsync(currentUserId, userEntity.Id, input.RoleIds);

                result.Code    = RESTStatus.Success;
                result.Message = "Add user successful";
            }
            else
            {
                if (id == null || Guid.Empty.Equals(id))
                {
                    throw new ArgumentException("The user id can not be null");
                }
                //TODO:Update the User
                var userEntity = await _userRepository.GetAsync(id);

                if (userEntity == null)
                {
                    result.Message = $"The user(id is {id}) doesn't exist";
                    return(result);
                }
                userEntity.AccountEmail   = input.AccountEmail;
                userEntity.AccountPhone   = input.AccountPhone;
                userEntity.ModifyByUserId = currentUserId;
                userEntity.ModifyTime     = DateTime.Now;
                await _userRepository.UpdateAsync(userEntity);

                //TODO:Update the user info;
                var userInfoEntity = (await _userInfoRepository.GetAllListAsync(item => item.UserId.Equals(id))).FirstOrDefault();
                if (userInfoEntity != null)
                {
                    var userInfoModel = Mapper.Map <UserInfoDto, UserInfo>(input.UserInfo);
                    userInfoModel.Id     = userInfoEntity.Id;
                    userInfoModel.UserId = id;
                    await _userInfoRepository.UpdateAsync(userInfoModel);
                }
                else
                {
                    //TODO:Add new Informations
                    var userinfoModel = Mapper.Map <UserInfoDto, UserInfo>(input.UserInfo);
                    userinfoModel.UserId = userEntity.Id;
                    await _userInfoRepository.InsertAsync(userinfoModel);
                }
                //
                //TODO:Update the department;
                await SetUserAndDepartmentMapAsync(currentUserId, userEntity.Id, input.DepartmentId);

                //TODO:Remove before user role;
                await RemoveBeforeUserRole(userEntity.Id);

                //TODO:update the role;
                await SetUserAndRoleMapAsync(currentUserId, userEntity.Id, input.RoleIds);

                result.Code    = RESTStatus.Success;
                result.Message = "update user successful";
            }

            return(result);
        }
Esempio n. 15
0
        public static void ReadRegInfo()
        {
            //2011.4.26 修改为从注册表获取
            RegistryKey hkml     = Registry.LocalMachine;
            RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
            RegistryKey aimdir   = software.OpenSubKey("IPSI", true);

            string tmp;

            string[] arytmp;

            //如果已经有使用过软件,通过注册表读取第一次使用时间+硬盘序列号+序列号
            if (aimdir != null && aimdir.GetValue("PatSI") != null)
            {
                try
                {
                    tmp = aimdir.GetValue("PatSI").ToString();
                    tmp = encryptDecryptStr(tmp);


                    //如果仅用|分割,在本身就含有|字符的时候可能会出现问题
                    string[] sep = new string[] { "@|#" };
                    arytmp = tmp.Split(sep, StringSplitOptions.RemoveEmptyEntries);
                    //arytmp = tmp.Split('|');

                    if (arytmp.Length >= 3)
                    {
                        //第一次使用时间
                        _FirstUsedTime = Convert.ToDateTime(arytmp[0]);
                        //最后一次使用时间
                        _LastUsedTime = Convert.ToDateTime(arytmp[1]);
                        //序列号
                        _SerialNo = arytmp[2];

                        #region 取生成时间和机器码

                        string strCreatDate = String.Empty;

                        strCreatDate = _SerialNo.Substring(_SerialNo.Length - 20, 10);
                        StrSqEndDate = _SerialNo.Substring(_SerialNo.Length - 10);
                        StrPC_SQM    = _SerialNo.Substring(0, _SerialNo.Length - 20);

                        #endregion
                        dtCreatDate = DateTime.Parse(strCreatDate);
                        dtSqEndDate = DateTime.Parse(StrSqEndDate).AddDays(1);

                        //DateTime dtWebHost

                        ////防止调整客户端时间,造成一直不过期的现象,要求重新注册
                        //if (!(DateTime.Now > _LastUsedTime && _LastUsedTime > _FirstUsedTime))
                        //{
                        //    #region 采取策略是强制过期还是保留使用时间差?

                        //    //使用强制过期,不满年直接变为满年
                        //    TimeSpan ts = (_LastUsedTime - _FirstUsedTime).Duration();
                        //    _FirstUsedTime = DateTime.Now.AddDays(-(ts.Days / nRegDay + 1) * nRegDay);
                        //    _LastUsedTime = DateTime.Now;

                        //    #endregion
                        //}
                    }
                    else
                    {   //针对仅有第一次试用时间,无注册码的情况
                        //_FirstUsedTime = Convert.ToDateTime(tmp);

                        //第一次使用时间
                        _FirstUsedTime = Convert.ToDateTime(arytmp[0]);
                        //最后一次使用时间
                        _LastUsedTime = Convert.ToDateTime(arytmp[1]);
                    }
                }
                catch (Exception)
                {
                    //如果注册表有键无值或者无法被正常处理,说明注册信息被破坏,直接将_FirstUsedTime改为随机年,造成使用年份变化,要求重新注册
                    Random r = new Random();
                    int    i = r.Next(2, 9);
                    _FirstUsedTime = DateTime.Now.AddDays(-nRegDay * i);
                    _LastUsedTime  = DateTime.Now;
                    _SerialNo      = String.Empty;
                }
            }
            else
            {
                //如果没有键但存在检索历史记录文件,说明删除过注册表信息,需要重新注册
                string shFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SearchHistory.txt");
                if (false && File.Exists(shFile))
                {
                    //将第一次使用时间置为检索记录文件创建时间,最后一次使用时间置为检索记录文件最后访问时间
                    FileInfo fi = new FileInfo(shFile);
                    _FirstUsedTime = fi.CreationTime;
                    _LastUsedTime  = fi.LastAccessTime;
                    _SerialNo      = String.Empty;
                }
                //否则就是第一次使用
                else
                {
                    _FirstUsedTime = DateTime.Now;
                    _LastUsedTime  = DateTime.Now;
                    _SerialNo      = String.Empty;
                }
            }

            //使用年份
            _UsedYear = ((int)(_LastUsedTime - _FirstUsedTime).TotalDays) / nRegDay + 1;
            //读取网卡Mac地址并加上使用年份
            _DiskNumber = _UsedYear + RegUtility.GetCpuNumber();


            //string strTmpYY = ((char)((Convert.ToInt32(_Cyear, 10) - 2001) + 'A')).ToString();
            _DiskNumber_2014 = _DiskNumber; // strCC + strTmpYY + _DiskNumber;
        }
Esempio n. 16
0
        private void button1_Click(object sender, EventArgs e)
        {
            //txbYzm.Text = DBA.Code.encrypt("I173387EFIE8");

            if (String.IsNullOrEmpty(txbJqh.Text))
            {
                MessageBox.Show("请完整填写注册信息!");
                txbJqh.Focus();
                return;
            }
            else
            {
                //原机器码
                string strDePcNm = DBA.Code.DecryptionAll(txbJqh.Text.Trim());

                //机器授权码
                string strPcNm_regNm = RegUtility.GetRegNumber(strDePcNm);

                //生成时间
                string strC_Date    = DateTime.Now.ToString("yyyy-MM-dd"); //yyyy-MM-dd HH:mm:ss
                string strSqjz_Date = dtPkSqEnd.Value.ToString("yyyy-MM-dd");

                //加密机器授权码及数据使用授权码[x|BegData|x|x]
                txbYzm.Text = DBA.Code.encrypt(strPcNm_regNm + strC_Date + strSqjz_Date);

                //复制注册码
                Clipboard.SetText(this.txbYzm.Text.Trim());
            }

            //增加授权记录
            using (StreamWriter sw = new StreamWriter(shFile, true))
            {
                //分别是时间、机器号、授权信息、注册码
                string strRegDtAndUInfo = DateTime.Now.ToString() + " 为 " + txbUserInfo.Text.Trim();
                string strRegJQH        = "机器号:" + txbJqh.Text.Trim();
                string strRegZCM        = "授权码:" + txbYzm.Text;

                string strRegAllInfo = string.Format("{0}\r\n{1}\r\n{2}\r\n{3}", strRegDtAndUInfo, strRegJQH, strRegZCM, "-------------------------------------------------");
                sw.WriteLine(strRegAllInfo);

                //加密
                //using (StreamWriter swReg = new StreamWriter(strRegKeyFile, true))
                //{
                //    PzCompression pzCom = PzCompressionHelper.getPzCompression(CompressionType.GZip);
                //    byte[] byTmp = pzCom.CompressToByte(strRegAllInfo);
                //    swReg.WriteLine(swReg);
                //}

                using (FileStream fsReg = new FileStream(strRegKeyFile, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    fsReg.Position = fsReg.Length;

                    PzCompression pzCom = PzCompressionHelper.getPzCompression(CompressionType.GZip);
                    byte[]        byTmp = pzCom.CompressToByte(strRegAllInfo);

                    byte[] byLen = System.BitConverter.GetBytes(byTmp.Length);

                    fsReg.Write(byLen, 0, byLen.Length);
                    fsReg.Write(byTmp, 0, byTmp.Length);
                }
            }
        }
Esempio n. 17
0
 private void Form1_DoubleClick(object sender, EventArgs e)
 {
     txbJqh.Text = RegUtility.GetDiskCPUNumber();
     txbYzm.Text = RegUtility.GetRegNumber(txbJqh.Text);
 }
Esempio n. 18
0
 private void radCpu_CheckedChanged(object sender, EventArgs e)
 {
     txbJqh.Text = RegUtility.GetCpuNumber();
     txbYzm.Text = RegUtility.GetRegNumber(txbJqh.Text);
 }