Skip to content

Commit

Permalink
feat: ✨ Check if the service already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
AntwortEinesLebens committed Oct 22, 2024
1 parent b9b19f9 commit f610ea2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/actions/drivers/byovd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ use clap::Parser;
use std::{error::Error, path::PathBuf};
use windows::{
core::{Owned, HSTRING, PCWSTR},
Win32::System::Services::{
CreateServiceW, OpenSCManagerW, StartServiceW, SC_HANDLE, SC_MANAGER_ALL_ACCESS,
SC_MANAGER_CREATE_SERVICE, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, SERVICE_KERNEL_DRIVER,
Win32::{
Foundation::GENERIC_READ,
System::Services::{
CreateServiceW, OpenSCManagerW, OpenServiceW, StartServiceW, SC_HANDLE,
SC_MANAGER_ALL_ACCESS, SC_MANAGER_CREATE_SERVICE, SERVICE_AUTO_START,
SERVICE_ERROR_IGNORE, SERVICE_KERNEL_DRIVER,
},
},
};

Expand Down Expand Up @@ -40,6 +44,16 @@ impl Runnable for Byovd {
SC_MANAGER_CREATE_SERVICE,
)?);

if OpenServiceW(
*service_manager,
&HSTRING::from(self.service_name.as_str()),
GENERIC_READ.0,
)
.is_ok()
{
return Ok(());
}

let service: Owned<SC_HANDLE> = Owned::new(CreateServiceW(
*service_manager,
&HSTRING::from(self.service_name.as_str()),
Expand Down

0 comments on commit f610ea2

Please sign in to comment.