注册表操作

 

 1 int CSysInfoHelper::RegisterStartFunction(const CString &valueName, 
 2                                           const CString &commondLine,
 3                                           HKEY hKey, 
 4                                           LPCTSTR lpSubKey)
 5 {
 6     //写入注册表,开机自启动 
 7     HKEY hkResult = NULL; 
 8 
 9     int result = -1;
10 
11     do 
12     {
13         DWORD dwDisposition = 0;
14         LONG lRet = RegCreateKeyEx(hKey, lpSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, 
15             NULL, &hkResult, &dwDisposition);
16         if (ERROR_SUCCESS != lRet)
17         {
18             break;
19         }
20 
21         lRet = RegSetValueEx(hkResult, valueName, 0, REG_SZ, (BYTE*)(const wchar_t*)commondLine, commondLine.GetLength() * sizeof(wchar_t));
22         if (ERROR_SUCCESS != lRet)
23         {
24             break;
25         }
26 
27         result = 1;
28 
29     } while (false);
30 
31     if (hkResult != NULL)
32     {
33         //关闭注册表 
34         RegCloseKey(hkResult); 
35     }
36 
37     return result;
38 }

 

 1 int CSysInfoHelper::IsFindKeyInRegedit(const CString &valueName, 
 2                                        HKEY hKey, 
 3                                        LPCTSTR lpSubKey)
 4 {
 5     //写入注册表,开机自启动 
 6     HKEY hkResult = NULL; 
 7 
 8     int result = -1;
 9 
10     do 
11     {
12         LONG lRet = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_READ, &hkResult);
13         if (ERROR_SUCCESS != lRet)
14         {
15             break;
16         }
17 
18         DWORD dwSize=0;
19         DWORD dwType=0;
20         lRet = RegQueryValueEx(hkResult, valueName, 0, &dwType, NULL, &dwSize);
21         if (ERROR_SUCCESS != lRet)
22         {
23             break;
24         }
25 
26         result = 1;
27 
28     } while (false);
29 
30     if (hkResult != NULL)
31     {
32         //关闭注册表 
33         RegCloseKey(hkResult); 
34     }
35 
36     return result;
37 }

 

posted @ 2015-05-19 10:05  醉游  阅读(234)  评论(0编辑  收藏  举报