-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlauncher.cpp
More file actions
38 lines (35 loc) · 939 Bytes
/
Copy pathlauncher.cpp
File metadata and controls
38 lines (35 loc) · 939 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
34
35
36
37
38
#include <Windows.h>
LPWSTR GetCurrentDirectory()
{
auto buffer = new wchar_t [MAX_PATH];
GetModuleFileNameW(nullptr, buffer, MAX_PATH);
wchar_t *c = buffer;
wchar_t *ptr = c;
while (*ptr) {
if (*ptr == '\\' || *ptr == '/') {
c = ptr;
}
ptr++;
}
*c = '\0';
return c;
}
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow)
{
SHELLEXECUTEINFOW info = {0};
info.cbSize = sizeof(SHELLEXECUTEINFOW);
info.fMask = SEE_MASK_NOCLOSEPROCESS;
info.hwnd = nullptr;
info.lpVerb = nullptr;
info.lpFile = L"cmd.exe";
info.lpParameters = LR"(/c "run.cmd")";
info.lpDirectory = GetCurrentDirectory();
info.nShow = SW_HIDE;
info.hInstApp = nullptr;
ShellExecuteExW(&info);
#ifdef WAIT_UNTIL_TERMINATE
WaitForSingleObject(info.hProcess, INFINITE);
#endif
CloseHandle(info.hProcess);
return 0;
}