0

试图将我的程序写入 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);
  }
4

2 回答 2

1
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 指针而不是一个指针)。

(虽然可能不是唯一的错误)

于 2014-02-19T23:54:57.993 回答
0

Spoke to a lecturer at my university, showed him My code he claims I need to run on an Administrator account, turns out my User on my laptop wasn't the admin(which I thought it was) will check if it works when I'm home and update

于 2014-02-20T13:50:02.980 回答