所以我试图在注册表项之后创建文件夹结构。这就是我到目前为止所做的事情
#include "stdafx.h"
#include "windows.h"
#define MAX_KEY_LENGTH 200
#define MAX_VALUE_NAME 16383
DWORD retCode;
void RecursiveQueryKey(HKEY hKey)
{
HKEY nextKey;
WCHAR achKey[MAX_KEY_LENGTH];
DWORD cbName;
DWORD retCode = NULL;
DWORD i=0;
while(retCode !=ERROR_NO_MORE_ITEMS)
{
cbName = MAX_KEY_LENGTH;
retCode = RegEnumKeyEx(hKey, i,achKey,&cbName,NULL,NULL,NULL,NULL);
if (retCode == ERROR_SUCCESS)
{
wprintf(L"(%d) %s\n", i+1, achKey);
WCHAR path[MAX_KEY_LENGTH];
wchar_t *wcsncat(wchar_t *path, const wchar_t *achKey, size_t n);
if(CreateDirectoryEx(TEXT("D:\\csso\\"),achKey, NULL) != 0){
wprintf(L"Directory created in D:\\csso\\%s\n", achKey);
} else {
printf("Directory failed with the error:");
}
wprintf(L"%d\n", GetLastError());
if(RegOpenKeyEx(hKey, achKey, 0, KEY_READ | KEY_WOW64_64KEY, &nextKey) == ERROR_SUCCESS)
{
RecursiveQueryKey(nextKey);
}
}
i++;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
HKEY hKey;
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Apple Inc."), 0, KEY_READ | KEY_WOW64_64KEY, &hKey) == ERROR_SUCCESS)
{
printf("RegOpenKeyEx() is OK!\n");
RecursiveQueryKey(hKey);
}
else
printf("RegOpenKeyEx() failed!\n");
RegCloseKey(hKey);
}
我对此很新,但是当我第一次运行该程序时,它表示该目录已全部创建,但它们不是,当我再次运行时,我收到错误 183 (已经存在) )。
我真的不确定这里有什么问题。
答案 0 :(得分:2)
好吧所以我弄明白了,问题来自于我无法创建路径,显然这很简单,这是我的最终代码,也许它会帮助别人。
#include "stdafx.h"
#include "windows.h"
#include "tchar.h"
#include <iostream>
#define KEY_LENGHT 255
#define MAX_VALUE_NAME 16000
#define DEFAULT_KEY L"Apple Inc."
WCHAR path[1024] = L"D:\\csso\\" DEFAULT_KEY;
void Query(HKEY key, WCHAR *path) {
HKEY next;
WCHAR name[KEY_LENGHT];
DWORD lpcname;
DWORD returncode = NULL;
DWORD i = 0;
WCHAR xpath[1024];
while(returncode != ERROR_NO_MORE_ITEMS) {
lpcname = KEY_LENGHT;
returncode =
RegEnumKeyEx(key, i, name, &lpcname, NULL, NULL, NULL, NULL);
if (returncode ==ERROR_SUCCESS) {
wcscpy(xpath, path);
wcscat(xpath, L"\\");
wcscat(xpath, name);
if(CreateDirectory(xpath, NULL)) {
wprintf(L"Creat Folder %s\n", xpath);
} else {
printf("Folder nu a putut fi creat! \n");
wprintf(L"%d\n", GetLastError());
}
DWORD verif =
RegOpenKeyEx(key, name, 0, KEY_READ | KEY_WOW64_64KEY, &next);
if(verif == ERROR_SUCCESS) {
Query(next, xpath);
}
i++;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
HKEY key;
DWORD verif =
RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\" DEFAULT_KEY), 0, KEY_READ | KEY_WOW64_64KEY, &key);
if(verif == ERROR_SUCCESS) {
printf("RegOpenKeyEx SUCCESS! \n");
if(!CreateDirectory(_T("D:\\csso\\" DEFAULT_KEY), NULL)) {
printf("Folder nu a putut fi creat! \n");
} else {
Query(key, path);
}
} else {
printf("RegOpenKeyEx FAIL! \n");
wprintf(L"%d\n", GetLastError);
}
RegCloseKey(key);
}
欢呼并祝你们好运。