-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpwsh.cpp
More file actions
36 lines (27 loc) · 802 Bytes
/
Copy pathpwsh.cpp
File metadata and controls
36 lines (27 loc) · 802 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
#include <windows.h>
#include <shlwapi.h>
#include <string>
int wmain()
{
auto commandLine = GetCommandLineW();
auto args = PathGetArgsW(commandLine);
if (*args && (wcscmp(args, L"--version") == 0 || wcscmp(args, L"-v") == 0))
{
wprintf(L"PowerShell 7.5.4\n");
return 0;
}
std::wstring command = L"powershell.exe ";
command += args;
STARTUPINFOW si = {sizeof(si)};
PROCESS_INFORMATION pi = {};
if (!CreateProcessW(nullptr, command.data(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi))
{
return GetLastError();
}
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD exitCode;
GetExitCodeProcess(pi.hProcess, &exitCode);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return exitCode;
}