代码
1 HKEY hSoftKey = NULL;
2 DWORD dw;
3 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\mysoft"), 0, KEY_WRITE|KEY_READ,&hSoftKey) != ERROR_SUCCESS){
4 hSoftKey = NULL;
5 if (RegCreateKeyEx(HKEY_CURRENT_USER,_T("Software\\mysoft"),0,REG_NONE,REG_OPTION_NON_VOLATILE,KEY_WRITE|KEY_READ,NULL,&hSoftKey,&dw) != ERROR_SUCCESS){
6 AfxMessageBox(L"写注册表失败");
7 if (hSoftKey != NULL)
8 {
9 RegCloseKey(hSoftKey);
10 }
11 return FALSE;
12 }
13 }
14 wchar_t ucode[MAX_PATH];
15 DWORD dwType = REG_SZ;
16 DWORD dwSize;
17 WCHAR tmpKeyCode[17] = {0};
18 if( RegQueryValueEx(hSoftKey , L"UCODE" , NULL , &dwType , (LPBYTE)ucode , &dwSize) == ERROR_SUCCESS ){
19 int curUcodeLen = wcslen(ucode) ;
20 for( int i = 0 ; i < 16 ; i++ ){
21 if(i>=curUcodeLen){
22 break;
23 }
24 tmpKeyCode[i] = ucode[i];
25 }
26 }else{
27 for( int i = 0 ; i < 16 ; i++ ){
28 tmpKeyCode[i] = code[ rand()%15 ];
29 }
30 if( RegSetValueEx(hSoftKey, L"UCODE",0,dwType, (LPBYTE)tmpKeyCode , (wcslen(tmpKeyCode) + 1)*sizeof(WCHAR) ) != ERROR_SUCCESS ){
31 AfxMessageBox(L"写注册表数值失败");
32 if (hSoftKey != NULL)
33 {
34 RegCloseKey(hSoftKey);
35 }
36 return FALSE;
37 }
38 }
39 if (hSoftKey != NULL)
40 {
41 RegCloseKey(hSoftKey);
42 }
2 DWORD dw;
3 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\mysoft"), 0, KEY_WRITE|KEY_READ,&hSoftKey) != ERROR_SUCCESS){
4 hSoftKey = NULL;
5 if (RegCreateKeyEx(HKEY_CURRENT_USER,_T("Software\\mysoft"),0,REG_NONE,REG_OPTION_NON_VOLATILE,KEY_WRITE|KEY_READ,NULL,&hSoftKey,&dw) != ERROR_SUCCESS){
6 AfxMessageBox(L"写注册表失败");
7 if (hSoftKey != NULL)
8 {
9 RegCloseKey(hSoftKey);
10 }
11 return FALSE;
12 }
13 }
14 wchar_t ucode[MAX_PATH];
15 DWORD dwType = REG_SZ;
16 DWORD dwSize;
17 WCHAR tmpKeyCode[17] = {0};
18 if( RegQueryValueEx(hSoftKey , L"UCODE" , NULL , &dwType , (LPBYTE)ucode , &dwSize) == ERROR_SUCCESS ){
19 int curUcodeLen = wcslen(ucode) ;
20 for( int i = 0 ; i < 16 ; i++ ){
21 if(i>=curUcodeLen){
22 break;
23 }
24 tmpKeyCode[i] = ucode[i];
25 }
26 }else{
27 for( int i = 0 ; i < 16 ; i++ ){
28 tmpKeyCode[i] = code[ rand()%15 ];
29 }
30 if( RegSetValueEx(hSoftKey, L"UCODE",0,dwType, (LPBYTE)tmpKeyCode , (wcslen(tmpKeyCode) + 1)*sizeof(WCHAR) ) != ERROR_SUCCESS ){
31 AfxMessageBox(L"写注册表数值失败");
32 if (hSoftKey != NULL)
33 {
34 RegCloseKey(hSoftKey);
35 }
36 return FALSE;
37 }
38 }
39 if (hSoftKey != NULL)
40 {
41 RegCloseKey(hSoftKey);
42 }