test-reg

BOOL CEverTestDlg::CheckExpire(void)  
{  
    COleDateTime expire = COleDateTime(2012,7,1,0,0,0);//过期时间  
    COleDateTime nowtime = COleDateTime::GetCurrentTime();//当前系统时间  
  
    //1.判断系统时间  
    if(nowtime >= expire)  
    {  
        return TRUE;  
    }  
  
    //2.判断  
    BYTE   buf[256];  
    HKEY   hKey;  
	HKEY   mKey;
    CString regPath = _T("SOFTWARE");  
    CString subKey = _T("0rz");  
    CString fullPath = regPath+_T("\\")+subKey;  
    CString regKey = _T("lic");  
    DWORD buflen =  sizeof(buf);  
  
    //打开注册表项,没有则创建  
    LONG   rt   =   RegOpenKeyEx(HKEY_LOCAL_MACHINE, fullPath,   0,   KEY_ALL_ACCESS,   &hKey);//打开全路径  
    if(rt != ERROR_SUCCESS)//打开失败  
    {  
        //准备创建  
        rt   =   RegOpenKeyEx(HKEY_LOCAL_MACHINE, regPath,   0,   KEY_ALL_ACCESS,   &hKey);//打开上级路径  
        if(rt != ERROR_SUCCESS)  
        {  
            AfxMessageBox(_T("注册错误[1001]"));  
            exit(1);  
        }  

		
  
        DWORD dw;  
        rt = RegCreateKeyEx(hKey, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &mKey, &dw);//创建子项  
        if(rt != ERROR_SUCCESS)  
        {  
            AfxMessageBox(_T("注册错误[1002]"));  
            exit(1);  
        }  
  
        RegCloseKey(hKey);  
		RegCloseKey(mKey);
		hKey = NULL;
        //hKey = mKey;  
	}  

	if(hKey == NULL)
	{
		//再次打开全路径
		rt   =   RegOpenKeyEx(HKEY_LOCAL_MACHINE, fullPath,   0,   KEY_ALL_ACCESS,   &hKey);//打开全路径  
		if(rt != ERROR_SUCCESS)
        {  
            AfxMessageBox(_T("注册错误[1003]"));  
            exit(1);  
        }     
	}
      
  
    //查询  
    memset(buf, 0, buflen);  
	//rt = RegQueryValue(hKey, subKey, buf, &buflen);
	DWORD type = REG_BINARY;
    rt = RegQueryValueEx(hKey,   regKey,   NULL,   &type,   (LPBYTE)&buf,   &buflen   );  
    if(rt != ERROR_SUCCESS)//目标值不存在  
    {  
        //写入目标值  
		time_t t = time(NULL);
		int size = sizeof(t);
		memcpy(buf, &t, size);
		int i;
		BYTE sum = 0;
		for(i=0; i<size; i++)
		{
			sum+=buf[i];
		}
		buf[size] = sum;

		rt = RegSetValueEx(hKey, regKey, 0, REG_BINARY, buf, size+1);
		if(rt != ERROR_SUCCESS)
		{
			AfxMessageBox(_T("注册错误[1004]"));  
            exit(1); 
		}
    }  
    RegCloseKey(hKey);  
    //ColeDateTime regtime = a;  
  
  
  
    return FALSE;  
}  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值