Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Fixed nssm not stopping correctly the windows service. Fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
organom committed Jan 8, 2019
1 parent ff971d0 commit 4b60084
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ public static bool DoesServiceExist(string serviceName, string machineName = "lo
return services.Any(s => s.ServiceName.Equals(serviceName));
}

public static void StopService(string serviceName, string machineName = "localhost")
{
var services = ServiceController.GetServices(machineName);
services.FirstOrDefault(s => s.ServiceName.Equals(serviceName) && s.Status != ServiceControllerStatus.Stopped)?.Stop();
}

public static void SetFolderAccessPermission(string directoryPath,string username)
{
var dirSecurity = Directory.GetAccessControl(directoryPath);
Expand Down
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private static bool InstallBeameGateKeeper(string token)
if (Helper.DoesServiceExist(gatekeeperName))
{
Console.WriteLine("--> removing windows service");
Helper.StartAndCheckReturn(nssmFile, "stop \"" + gatekeeperName + "\"");
Helper.StopService(gatekeeperName);
Helper.StartAndCheckReturn(nssmFile, "remove \"" + gatekeeperName + "\" confirm");
}

Expand Down

0 comments on commit 4b60084

Please sign in to comment.