gpt4 book ai didi

C 编程写入注册表不起作用? RegSetValueEX 错误

转载 作者:行者123 更新时间:2023-11-30 15:38:11 24 4
gpt4 key购买 nike

尝试将我的程序写入 Windows 注册表,但我的代码告诉我在执行 RegSetValueEX() 时出现错误。我有管理权限。我根本看不出出了什么问题,而且我一整天都盯着 REG 上的 MSDN 页面。

int StartupKey()
{
int StartupKey;
long RegOpenResult, result_write;
const char *FilePath[]= "C:\\Windows\\security\\BensKlog.exe";
LPCSTR Klog = "BensKLOG";

HKEY hkey;
printf("Opening Key...\n");
RegOpenResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS, &hkey);
if(RegOpenResult != ERROR_SUCCESS) {
if(RegOpenResult == ERROR_FILE_NOT_FOUND) {
printf("Not found\n");
} else {
printf("Error Opening Key\n");
}
} else {
printf("SUCCESS!!!\n");
}
StartupKey=RegCreateKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",&hkey);

printf("Writing Value named Klog\n");
result_write = RegSetValueEx((HKEY)hkey,Klog,0,REG_SZ,(BYTE *)FilePath,strlen(FilePath));
if(result_write != ERROR_SUCCESS) {
printf("Error Writing Value\n");
} else {
printf("SUCCESS!!!\n");
}
RegCloseKey(hkey);
}

最佳答案

const char *FilePath[]= "C:\\Windows\\security\\BensKlog.exe";

使用其中之一:

const char FilePath[] = "C:\\Windows\\security\\BensKlog.exe";

const char *FilePath = "C:\\Windows\\security\\BensKlog.exe";

但不要混合它们(您的代码定义了一组 const char 指针而不是一个指针)。

(但可能不是唯一的错误)

关于C 编程写入注册表不起作用? RegSetValueEX 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21894986/

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