diff options
| author | Odd Stranne <odd@mullvad.net> | 2018-09-10 10:20:59 +0200 |
|---|---|---|
| committer | Odd Stranne <odd@mullvad.net> | 2018-09-12 13:20:20 +0200 |
| commit | 589bfd82c848a8c35a8a43adaf05044167bd654a (patch) | |
| tree | 7d85c8fd90b535e03796ba66399f683172701797 /windows | |
| parent | 3c82d1f23f2b52559e0894a4203bcdfa0734c494 (diff) | |
| download | mullvadvpn-589bfd82c848a8c35a8a43adaf05044167bd654a.tar.xz mullvadvpn-589bfd82c848a8c35a8a43adaf05044167bd654a.zip | |
Use absolute path for 'netsh.exe'
Diffstat (limited to 'windows')
| -rw-r--r-- | windows/windns/src/windns/netsh.cpp | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/windows/windns/src/windns/netsh.cpp b/windows/windns/src/windns/netsh.cpp index fc46d824c2..7c031db87e 100644 --- a/windows/windns/src/windns/netsh.cpp +++ b/windows/windns/src/windns/netsh.cpp @@ -2,12 +2,35 @@ #include "netsh.h" #include "libcommon/applicationrunner.h" #include "libcommon/string.h" +#include "libcommon/filesystem.h" #include <sstream> #include <stdexcept> +#include <experimental/filesystem> namespace { +std::wstring g_NetShPath; + +void InitializePath() +{ + if (false == g_NetShPath.empty()) + { + return; + } + + const auto system32 = common::fs::GetKnownFolderPath(FOLDERID_System, 0, nullptr); + + g_NetShPath = std::experimental::filesystem::path(system32).append(L"netsh.exe"); +} + +const std::wstring &NetShPath() +{ + InitializePath(); + + return g_NetShPath; +} + std::vector<std::string> BlockToRows(const std::string &textBlock) { // @@ -95,7 +118,7 @@ void NetSh::SetIpv4PrimaryDns(uint32_t interfaceIndex, std::wstring server) << server << L" validate=no"; - auto netsh = common::ApplicationRunner::StartWithoutConsole(L"netsh.exe", ss.str()); + auto netsh = common::ApplicationRunner::StartWithoutConsole(NetShPath(), ss.str()); ValidateShellOut(*netsh); } @@ -117,7 +140,7 @@ void NetSh::SetIpv4SecondaryDns(uint32_t interfaceIndex, std::wstring server) << server << L" index=2 validate=no"; - auto netsh = common::ApplicationRunner::StartWithoutConsole(L"netsh.exe", ss.str()); + auto netsh = common::ApplicationRunner::StartWithoutConsole(NetShPath(), ss.str()); ValidateShellOut(*netsh); } @@ -137,7 +160,7 @@ void NetSh::SetIpv4Dhcp(uint32_t interfaceIndex) << interfaceIndex << L" source=dhcp"; - auto netsh = common::ApplicationRunner::StartWithoutConsole(L"netsh.exe", ss.str()); + auto netsh = common::ApplicationRunner::StartWithoutConsole(NetShPath(), ss.str()); ValidateShellOut(*netsh); } @@ -159,7 +182,7 @@ void NetSh::SetIpv6PrimaryDns(uint32_t interfaceIndex, std::wstring server) << server << L" validate=no"; - auto netsh = common::ApplicationRunner::StartWithoutConsole(L"netsh.exe", ss.str()); + auto netsh = common::ApplicationRunner::StartWithoutConsole(NetShPath(), ss.str()); ValidateShellOut(*netsh); } @@ -181,7 +204,7 @@ void NetSh::SetIpv6SecondaryDns(uint32_t interfaceIndex, std::wstring server) << server << L" index=2 validate=no"; - auto netsh = common::ApplicationRunner::StartWithoutConsole(L"netsh.exe", ss.str()); + auto netsh = common::ApplicationRunner::StartWithoutConsole(NetShPath(), ss.str()); ValidateShellOut(*netsh); } @@ -201,7 +224,7 @@ void NetSh::SetIpv6Dhcp(uint32_t interfaceIndex) << interfaceIndex << L" source=dhcp"; - auto netsh = common::ApplicationRunner::StartWithoutConsole(L"netsh.exe", ss.str()); + auto netsh = common::ApplicationRunner::StartWithoutConsole(NetShPath(), ss.str()); ValidateShellOut(*netsh); } |
