mirror of
https://github.com/es3n1n/defendnot.git
synced 2026-08-02 10:32:01 +00:00
feat(loader): check for wsc service before starting
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "core/core.hpp"
|
||||
|
||||
#include "shared/ctx.hpp"
|
||||
#include "shared/names.hpp"
|
||||
#include "shared/strings.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <print>
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
namespace loader {
|
||||
namespace {
|
||||
constexpr std::string_view kTaskName = names::kProjectName;
|
||||
constexpr std::string_view kTaskName = strings::kProjectName;
|
||||
|
||||
/// A very basic implementation, a lot of stuff is missing
|
||||
template <typename Ty>
|
||||
@@ -164,7 +164,7 @@ namespace loader {
|
||||
principal->put_RunLevel(TASK_RUNLEVEL_HIGHEST);
|
||||
|
||||
/// Info
|
||||
reg_info->put_Author(bstr_t(names::kRepoUrl.data()));
|
||||
reg_info->put_Author(bstr_t(strings::kRepoUrl.data()));
|
||||
|
||||
/// Start even if we're on batteries
|
||||
settings->put_DisallowStartIfOnBatteries(VARIANT_FALSE);
|
||||
|
||||
@@ -24,4 +24,5 @@ namespace loader {
|
||||
[[nodiscard]] HANDLE inject(std::string_view dll_path, std::string_view proc_name);
|
||||
[[nodiscard]] bool add_to_autorun(AutorunType type);
|
||||
[[nodiscard]] bool remove_from_autorun();
|
||||
void ensure_environment();
|
||||
} // namespace loader
|
||||
|
||||
26
defendnot-loader/core/ensure_environment.cpp
Normal file
26
defendnot-loader/core/ensure_environment.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "core/core.hpp"
|
||||
#include "shared/strings.hpp"
|
||||
#include "util/scm.hpp"
|
||||
|
||||
#include <format>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace loader {
|
||||
void ensure_environment() {
|
||||
auto manager = scm::Manager();
|
||||
if (!manager.valid()) [[unlikely]] {
|
||||
throw std::runtime_error("Unable to open scm::Manager");
|
||||
}
|
||||
|
||||
auto service = manager.get_service(L"wscsvc");
|
||||
if (!service.valid() || !service.query_status()) {
|
||||
throw std::runtime_error(strings::wsc_unavailable_error().data());
|
||||
}
|
||||
|
||||
const auto state = service.state();
|
||||
if (state != scm::ServiceState::RUNNING) {
|
||||
throw std::runtime_error(std::format("{}\nService state: {}, but should be RUNNING", strings::wsc_unavailable_error(),
|
||||
scm::kServiceStateNames[static_cast<std::underlying_type_t<scm::ServiceState>>(state)]));
|
||||
}
|
||||
}
|
||||
} // namespace loader
|
||||
Reference in New Issue
Block a user