-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
33 lines (29 loc) · 817 Bytes
/
Main.cpp
File metadata and controls
33 lines (29 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
struct IUnknown;
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <comdef.h>
int MainAdmin(PWSTR pCmdLine, int nCmdShow)
{
STARTUPINFOW startupInfo = {};
startupInfo.cb = sizeof(startupInfo);
startupInfo.dwFlags |= STARTF_USESHOWWINDOW;
startupInfo.wShowWindow = nCmdShow;
BOOL okay;
PROCESS_INFORMATION processInformation = {};
wchar_t systemDirectory[MAX_PATH];
GetSystemDirectoryW(&systemDirectory[0], MAX_PATH);
_bstr_t path;
path += "\"";
path += systemDirectory;
path += "\\notepad.exe\" ";
path += pCmdLine;
okay = CreateProcess(NULL, path, NULL, NULL, false, 0, NULL, NULL, &startupInfo, &processInformation);
DWORD lastErr = GetLastError();
if (okay)
{
CloseHandle(processInformation.hProcess);
CloseHandle(processInformation.hThread);
}
return !okay;
}