- UID
- 77
- 精华
- 积分
- 9486
- 威望
- 点
- 宅币
- 个
- 贡献
- 次
- 宅之契约
- 份
- 最后登录
- 1970-1-1
- 在线时间
- 小时
|
- DWORD RegDeleteKeys(HKEY RootKey, const char *pSubKey, bool InitVar)
- {
- HKEY hKey;
- DWORD nRet,NameCnt,NameMaxLen,KeyCnt,KeyMaxLen,MaxDateLen;
- static int dwDeep = -1;
- if(InitVar)
- dwDeep = -1;
- else
- dwDeep++;
- nRet=RegOpenKeyEx(RootKey,pSubKey,0,KEY_ALL_ACCESS,&hKey);
- if(nRet!=ERROR_SUCCESS)
- {
- return 0;
- }
- nRet = RegQueryInfoKey(hKey,NULL,NULL,NULL,&KeyCnt,&KeyMaxLen,NULL,&NameCnt,&NameMaxLen,&MaxDateLen,NULL,NULL);
- if(nRet == ERROR_SUCCESS)
- {
- for(int dwIndex = KeyCnt - 1; dwIndex >= 0; dwIndex--) //枚举键值
- {
- char sKeyName[256] = {0}, pSubKeyTemp[256] = {0};
- RegEnumKey(hKey, dwIndex, sKeyName, sizeof(sKeyName));
- HKEY hKeySub;
- DWORD KeyCntSub;
- strcpy(pSubKeyTemp, pSubKey);
- strcat(pSubKeyTemp, "\");
- strcat(pSubKeyTemp, sKeyName);
- nRet = RegOpenKeyEx(RootKey,pSubKeyTemp,0,KEY_ALL_ACCESS,&hKeySub);
- if(nRet == ERROR_SUCCESS)
- {
- nRet = RegQueryInfoKey(hKeySub,NULL,NULL,NULL,&KeyCntSub,&KeyMaxLen,NULL,&NameCnt,&NameMaxLen,&MaxDateLen,NULL,NULL);
- if(nRet == ERROR_SUCCESS)
- {
- if (KeyCntSub != 0)
- {
- RegDeleteKeys(RootKey, pSubKeyTemp,0);
- }
- RegCloseKey(hKeySub);
- }
- }
- RegDeleteKey(RootKey ,pSubKeyTemp);
- }
- RegCloseKey(hKey);
- }
- RegDeleteKey(RootKey ,pSubKey);
- return 0;
- }
复制代码 测试:- RegDeleteKeys(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\services\\WIN64AST",1);
- RegDeleteKeys(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet002\\services\\WIN64AST",1);
复制代码 |
|