-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
55 lines (44 loc) · 1.7 KB
/
Utils.cpp
File metadata and controls
55 lines (44 loc) · 1.7 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "Utils.h"
#include "WhitespaceParser.h"
//#################################################################################################
HRESULT ComInit(const bool bMultithreaded)
{
return CoInitializeEx(nullptr, bMultithreaded ? COINIT_MULTITHREADED : COINIT_APARTMENTTHREADED);
}
//#################################################################################################
HRESULT ComInitEx(const bool bMultithreaded, const DWORD dwAuthnLevel)
{
HRESULT hr = CoInitializeEx(nullptr, bMultithreaded ? COINIT_MULTITHREADED : COINIT_APARTMENTTHREADED);
if(SUCCEEDED(hr))
hr = CoInitializeSecurity(nullptr, -1, nullptr, nullptr, dwAuthnLevel, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, EOAC_NONE, nullptr);
return hr;
}
//#################################################################################################
void ComFree(void)
{
CoUninitialize();
}
//#################################################################################################
std::wstring GetProcessFilename(const uint32_t nPid)
{
std::wstring strFilename;
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, nPid);
if(hProcess)
{
wchar_t szName[1024] = {0};
DWORD dwLen = 1024;
if(QueryFullProcessImageNameW(hProcess, 0, szName, &dwLen))
strFilename = szName;
CloseHandle(hProcess);
}
return strFilename;
}
//#################################################################################################
std::vector<CStr> GetCommandLineArguments(void)
{
std::vector<CStr> vecArgs;
CWhitespaceParser cmdline(GetCommandLineW());
for(size_t n = 0; n < cmdline.GetCount(); ++n)
vecArgs.push_back(cmdline.Get(n));
return vecArgs;
}