MCPcopy Create free account
hub / github.com/Windscribe/Desktop-App / installService

Method installService

src/helper/windows/wireguard/wireguardcontroller.cpp:38–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38bool WireGuardController::installService(bool isAmneziaWG)
39{
40 isAmneziaWG_ = isAmneziaWG;
41 isInitialized_ = false;
42 try {
43 exeName_ = L"WireguardService.exe";
44 const std::wstring confFile = configFile();
45 if (confFile.empty()) {
46 return false;
47 }
48
49 std::wstring serviceCmdLine;
50 {
51 std::wostringstream stream;
52 stream << L"\"" << Utils::getExePath() << L"\\" << exeName_ << "\" \"" << confFile << L"\"";
53 if (isAmneziaWG) {
54 stream << " --amneziawg";
55 }
56 serviceCmdLine = stream.str();
57 }
58
59 wsl::ServiceControlManager svcCtrl;
60 svcCtrl.openSCM(SC_MANAGER_ALL_ACCESS);
61
62 if (svcCtrl.isServiceInstalled(kWireGuardServiceIdentifier.c_str())) {
63 spdlog::info("WireGuardController::installService - deleting existing WireGuard service");
64 std::error_code ec;
65 if (!svcCtrl.deleteService(kWireGuardServiceIdentifier.c_str(), ec)) {
66 spdlog::error("WireGuardController::installService - failed to delete existing WireGuard service ({})", ec.value());
67 }
68 }
69
70#if defined(USE_SIGNATURE_CHECK)
71 ExecutableSignature sigCheck;
72 std::wstring servicePath = Utils::getExePath() + L"\\" + exeName_;
73 if (!sigCheck.verify(servicePath)) {
74 spdlog::error("WireGuard service signature incorrect: {}", sigCheck.lastError());
75 return false;
76 }
77#endif
78
79 svcCtrl.installService(kWireGuardServiceIdentifier.c_str(), serviceCmdLine.c_str(),
80 WS_PRODUCT_NAME_W L" Wireguard Tunnel", L"Manages the " WS_PRODUCT_NAME_W L" WireGuard tunnel connection",
81 SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START, L"Nsi\0TcpIp\0", true);
82
83 svcCtrl.setServiceSIDType(SERVICE_SID_TYPE_UNRESTRICTED);
84
85 isInitialized_ = true;
86 }
87 catch (std::system_error& ex) {
88 spdlog::error("WireGuardController::installService - {}", ex.what());
89 }
90
91 return isInitialized_;
92}
93
94bool WireGuardController::configure(const std::wstring &config)
95{

Callers 3

executeMethod · 0.45
startWireGuardFunction · 0.45

Calls 7

openSCMMethod · 0.80
isServiceInstalledMethod · 0.80
setServiceSIDTypeMethod · 0.80
getExePathFunction · 0.50
deleteServiceMethod · 0.45
verifyMethod · 0.45
lastErrorMethod · 0.45

Tested by

no test coverage detected