-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandExecution.h
31 lines (25 loc) · 987 Bytes
/
CommandExecution.h
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
#pragma once
#include <atlstr.h>
#include <Windows.h>
#include <vector>
#include <future>
using namespace ATL;
class CommandExecution
{
public:
struct CommandResult {
DWORD result = -1;
CString errorMsg;
CString successMsg;
};
// 同步方法
static CommandResult ExecCommand(const CString& command, bool asAdmin = false);
static CommandResult ExecCommand(const std::vector<CString>& commands, bool asAdmin = false);
// 异步方法
static std::future<CommandResult> ExecCommandAsync(const CString& command, bool asAdmin = false);
static std::future<CommandResult> ExecCommandAsync(const std::vector<CString>& commands, bool asAdmin = false);
private:
static CommandResult ExecuteCommands(const CString& commandLine, bool asAdmin);
static void AsyncExecutor(const CString& commandLine, bool asAdmin, std::promise<CommandResult>&& resultPromise);
static CString EscapePowerShellCommand(const CString& command);
};