• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_WIN_ELEVATION_UTIL_H_
6 #define BASE_WIN_ELEVATION_UTIL_H_
7 
8 #include <string>
9 
10 #include "base/base_export.h"
11 #include "base/process/process.h"
12 #include "base/process/process_handle.h"
13 #include "base/win/windows_types.h"
14 
15 namespace base {
16 class CommandLine;
17 }  // namespace base
18 
19 namespace base::win {
20 
21 // Returns the process id for `explorer.exe`.
22 BASE_EXPORT ProcessId GetExplorerPid();
23 
24 // Returns `true` if `process_id` is running at medium integrity.
25 BASE_EXPORT bool IsProcessRunningAtMediumOrLower(ProcessId process_id);
26 
27 // Runs `command_line` de-elevated and returns the spawned process. Returns an
28 // invalid process on failure. `::GetLastError` can be used to get the last
29 // error in the failure case.
30 BASE_EXPORT Process RunDeElevated(const CommandLine& command_line);
31 
32 // Runs `command_line` de-elevated. The function does not wait for the spawned
33 // process.
34 BASE_EXPORT HRESULT RunDeElevatedNoWait(const CommandLine& command_line);
35 
36 // Runs `path` de-elevated using `IShellDispatch2::ShellExecute`. `path`
37 // specifies the file or object on which to execute the default verb (typically
38 // "open"). If `path` specifies an executable file, `parameters` specifies the
39 // parameters to be passed to the executable. The function does not wait for the
40 // spawned process.
41 BASE_EXPORT HRESULT RunDeElevatedNoWait(const std::wstring& path,
42                                         const std::wstring& parameters);
43 
44 }  // namespace base::win
45 
46 #endif  // BASE_WIN_ELEVATION_UTIL_H_
47