aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/winapi/process.hpp
blob: 5c9e3c96d1c59693eddb0e442e5db94a59636a22 (plain) (blame)
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
// Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
// This file is part of the "winapi-common" project.
// For details, see https://github.com/egor-tensin/winapi-common.
// Distributed under the MIT License.

#pragma once

#include "cmd_line.hpp"
#include "handle.hpp"
#include "process_io.hpp"
#include "resource.hpp"

#include <boost/config.hpp>

#include <windows.h>

#include <string>
#include <utility>

namespace winapi {

class Process {
public:
    static Process create(const CommandLine&);
    static Process create(const CommandLine&, process::IO);

    static Process runas(const CommandLine&);

    bool is_running() const;
    void wait() const;
    void terminate(int ec = 0) const;
    void shut_down(int ec = 0) const;
    int get_exit_code() const;

    static std::string get_exe_path();

    static Resource get_resource(unsigned int id);
    static std::string get_resource_string(unsigned int id);

private:
    explicit Process(Handle&& handle) : m_handle{std::move(handle)} {}

    static HMODULE get_exe_module();

    Handle m_handle;
};

} // namespace winapi