|
#include <windows.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(int argc, wchar_t* argv[])
{
// Build the fully-qualified pathname to the driver's image
vector<wchar_t> buffer(MAX_PATH);
GetCurrentDirectory(static_cast<int>(buffer.capacity()), &buffer[0]);
wstring path;
path.append(L"\\\\?\\");
path.append(&buffer[0]);
path.append(L"\\NoDeleteDelay.sys");
// Make sure the file exists
if (GetFileAttributes(path.c_str()) == INVALID_FILE_ATTRIBUTES)
{
cout << "File not found: " << path.c_str() << endl;
return 1;
}
// Open the Service Control Manager
SC_HANDLE hSc = OpenSCManager(NULL, NULL, GENERIC_READ | GENERIC_WRITE);
if (hSc == NULL)
{
cout << "Error calling OpenSCManager: " << GetLastError() << endl;
return 1;
}
// Create the service
SC_HANDLE hService = CreateService(
hSc,
L"NoDeleteDelay",
L"NoDeleteDelay",
GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE,
SERVICE_KERNEL_DRIVER,
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
path.c_str(),
NULL,
NULL,
NULL,
NULL,
L""
);
if (hService == NULL)
{
cout << "Error calling CreateService: " << GetLastError() << endl;
return 1;
}
cout << "Service created." << endl;
// Start the service
if (!StartService(hService, 0, NULL))
{
cout << "Error calling StartService: " << GetLastError() << endl;
return 1;
}
cout << "Service started." << endl;
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.