#include <iostream>
#include <Windows.h>
#include <string>
#include <winioctl.h>
#include <TlHelp32.h>

#define IOCTL_LOAD_DRIVER CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
#define IOCTL_UNLOAD_DRIVER CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)

using namespace std;

int main()
{
	HANDLE hDevice = CreateFileA("\\\\.\\MyDriver", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hDevice == INVALID_HANDLE_VALUE)
	{
		cout << "CreateFileA failed: " << GetLastError() << endl;
		return 1;
	}

	DWORD dwReturn = 0;
	if (!DeviceIoControl(hDevice, IOCTL_LOAD_DRIVER, "C:\\Windows\\System32\\drivers\\MyDriver.sys", strlen("C:\\Windows\\System32\\drivers\\MyDriver.sys") + 1, NULL, 0, &dwReturn, NULL))
	{
		cout << "DeviceIoControl failed: " << GetLastError() << endl;
		return 1;
	}

	CloseHandle(hDevice);

	return 0;
}

// And fuck you too