shell_path.hpp
Go to the documentation of this file.
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 
10 #pragma once
11 
12 #include <boost/process/config.hpp>
13 #include <boost/system/error_code.hpp>
14 #include <filesystem>
15 #include <Windows.h>
16 
18 {
19 
20  inline std::filesystem::path shell_path()
21  {
22  TCHAR sysdir[MAX_PATH];
23  UINT size = ::GetSystemDirectory(sysdir, sizeof(sysdir));
24  if (!size)
25  {
26  BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("GetSystemDirectory() failed");
27  }
28  std::filesystem::path p = sysdir;
29  return p / "cmd.exe";
30  }
31 
32  inline std::filesystem::path shell_path(boost::system::error_code& ec)
33  {
34  TCHAR sysdir[MAX_PATH];
35  UINT size = ::GetSystemDirectory(sysdir, sizeof(sysdir));
36  std::filesystem::path p;
37  if (!size)
38  {
39  BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
40  }
41  else
42  {
43  ec.clear();
44  p = sysdir;
45  p /= "cmd.exe";
46  }
47  return p;
48  }
49 
50 }
boost::process::windows
Definition: child.hpp:15
config.hpp
boost::process::windows::shell_path
std::filesystem::path shell_path()
Definition: shell_path.hpp:20