Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C、 Windows API在注册表项后创建文件夹结构_C_Windows_Api_Directory_Registry - Fatal编程技术网

C、 Windows API在注册表项后创建文件夹结构

C、 Windows API在注册表项后创建文件夹结构,c,windows,api,directory,registry,C,Windows,Api,Directory,Registry,因此,我试图在注册表项之后创建一个文件夹结构。这就是我到目前为止所做的 #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

因此,我试图在注册表项之后创建一个文件夹结构。这就是我到目前为止所做的

#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(已经存在)


我真的不确定这里的问题是什么。

好吧,我想出来了,问题是因为我无法创建路径,显然这很简单,这是我的最终代码,也许它会帮助别人

#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);
}
#包括“stdafx.h”
#包括“windows.h”
#包括“tchar.h”
#包括
#定义键长度255
#定义最大值名称16000
#定义默认键L“苹果公司”
WCHAR路径[1024]=L“D:\\csso\\”默认\u键;
无效查询(HKEY键,WCHAR*路径){
香港大学教育学院下一期;
WCHAR名称[关键长度];
DWORD lpcname;
DWORD returncode=NULL;
dwordi=0;
wcharxpath[1024];
while(returncode!=错误\u无\u更多\u项){
lpcname=键长;
返回码=
RegEnumKeyEx(key、i、name和lpcname、NULL、NULL、NULL、NULL);
if(returncode==错误\成功){
wcscpy(xpath,path);
wcscat(xpath,L“\\”);
wcscat(xpath,名称);
if(CreateDirectory(xpath,NULL)){
wprintf(L“创建文件夹%s\n”,xpath);
}否则{
printf(“文件夹nu a putut fi creat!\n”);
wprintf(L“%d\n”,GetLastError());
}
DWORD verif=
RegOpenKeyEx(key,name,0,key|u READ | key_WOW64_64KEY,&next);
if(verif==错误\u成功){
查询(下一步,xpath);
}
i++;
}
}
}
int _tmain(int argc,_TCHAR*argv[]
{
香港海关关卡;
DWORD verif=
RegOpenKeyEx(HKEY_本地_机器,文本(“软件\\”默认_键),0,键读取|键WOW64_64键和键);
if(verif==错误\u成功){
printf(“RegOpenKeyEx成功!\n”);
如果(!CreateDirectory(\u T(“D:\\csso\\”默认\u键),则为NULL)){
printf(“文件夹nu a putut fi creat!\n”);
}否则{
查询(键、路径);
}
}否则{
printf(“RegOpenKeyEx失败!\n”);
wprintf(L“%d\n”,GetLastError);
}
RegCloseKey(key);
}
干杯,祝你们好运