#include <windows.h>
#include <windowsX.h>
#include <iostream>
using namespace std;
static char path;
void WndProc_OnDestroy(HWND hWnd)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
// Создадим другой процесс, а этот благополучно завершим.
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
CreateProcessA(NULL, (LPSTR)"testH.exe", NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
PostQuitMessage(0);
//return FORWARD_WM_DESTROY(hWnd, DefWindowProc);
}
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
//HANDLE_MSG(hWnd, WM_CREATE, WndProc_OnCreate);
HANDLE_MSG(hWnd, WM_DESTROY, WndProc_OnDestroy);
//HANDLE_MSG(hWnd, WM_SIZE, WndProc_OnSize);
//HANDLE_MSG(hWnd, WM_COMMAND, WndProc_OnCommand);
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
while (GetMessageA(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
WndProc(msg.hwnd, msg.message, msg.wParam, msg.lParam);
DispatchMessage(&msg);
}
return msg.wParam;
}
bool addToAutorun(string path) {
HKEY hKey;
if (RegCreateKeyExA(HKEY_LOCAL_MACHINE, (LPCSTR)"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\", NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS) {
if (RegSetValueA(hKey, "test", REG_SZ, (LPCSTR)path.c_str(), path.size() + 1) == ERROR_SUCCESS) {
RegCloseKey(hKey);
return TRUE;
}
else {
RegCloseKey(hKey);
return FALSE;
}
}
else {
RegCloseKey(hKey);
return FALSE;
}
}
bool addToAutorun(string path) {
HKEY hKey;
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, (LPCSTR)"SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_WOW64_32KEY | KEY_SET_VALUE, NULL, &hKey, NULL) == ERROR_SUCCESS) {
if (RegSetValueA(hKey, "test", REG_SZ, (LPCSTR)path.c_str(), path.size() + 1) == ERROR_SUCCESS) {
RegCloseKey(hKey);
return TRUE;
}
else {
RegCloseKey(hKey);
return FALSE;
}
}
else {
RegCloseKey(hKey);
return FALSE;
}