gpt4 book ai didi

c++ - 从文件导入注册表

转载 作者:行者123 更新时间:2023-11-28 03:02:06 27 4
gpt4 key购买 nike

我在从文件导入注册表时遇到两个问题。

我使用 regedit.exe 导入我的注册表文件:

string file = "regedit.exe /s D://ImageArchiveHour-1207150440.reg";
const char* ctv = file.c_str();

bool result = system(ctv);

在我的例子中,注册表文件导入成功,但是结果为false。如何获取导入结果?

另一个问题是,如果我的注册表文件路径包含SPACE,导入将失败。

例如:

string file = "regedit.exe /s D://New Folder//ImageArchiveHour-1207150440.reg";
const char* ctv = file.c_str();

system(ctv);

如您所见,新文件夹中有空间。

我应该如何解决这个问题?或者还有其他方法吗?

最佳答案

0 是导入的结果。 system返回 -1 错误,但请参阅链接以了解可能的返回值。如果一切正常,它将返回 regedit 操作的退出代码,0 = ERROR_SUCCESS .

If command is NULL and the command interpreter is found, returns a nonzero value. If the command interpreter is not found, returns 0 and sets errno to ENOENT. If command is not NULL, system returns the value that is returned by the command interpreter. It returns the value 0 only if the command interpreter returns the value 0. A return value of – 1 indicates an error, and errno is set to one of the following values:...

由于 command line parameters are parsed 方式,操作失败并显示空格.您需要用引号将您的路径括起来(参见 MSDN C++ Character Literals )。

所以你的

string file = "regedit.exe/s D://ImageArchiveHour-1207150440.reg";

会是

string file = "regedit.exe/s\"D://ImageArchiveHour-1207150440.reg\"";

关于c++ - 从文件导入注册表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20517171/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com