Skip to content

Commit

Permalink
Added built in accounts and pack script. Readme updated to reflect th…
Browse files Browse the repository at this point in the history
…ese changes
  • Loading branch information
PeterKottas committed Nov 27, 2017
1 parent a58da48 commit 3d10ad2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ Community, feel encouraged to add more templates if you find something missing/u
8. Run the service with **action:start** and it will start the service.
9. Run the service with **action:stop** and it will stop the service.
10. Run the service with **username:YOUR_USERNAME**, **password:YOUR_PASSWORD** and **action:install** which installs it for the given account.
11. Run the service with **description:YOUR_DESCRIPTION** and it setup description for the service.
11. Run the service with **displayName:YOUR_DISPLAY_NAME** and it setup Display name for the service.
12. Run the service with **name:YOUR_NAME** and it setup name for the service.
13. You can find the complete example in PeterKottas.DotNetCore.Example project.
14. Install the service using powershell: New-Service -Name $serviceName -BinaryPathName "$binPath action:run" -StartupType Automatic
11. Run the service with **built-in-account:(NetworkService|LocalService|LocalSystem)** and **action:install** which installs it for the given built in account. Defaults to **LocalSystem**.
12. Run the service with **description:YOUR_DESCRIPTION** and it setup description for the service.
13. Run the service with **displayName:YOUR_DISPLAY_NAME** and it setup Display name for the service.
14. Run the service with **name:YOUR_NAME** and it setup name for the service.
15. Run the service with **start-immediately:(true|false)** to start service immediately after install. Defaults to **true**.
16. You can find the complete example in PeterKottas.DotNetCore.Example project.
17. Install the service using powershell: New-Service -Name $serviceName -BinaryPathName "$binPath action:run" -StartupType Automatic

## Contributing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using PeterKottas.DotNetCore.WindowsService.Enums;
using PeterKottas.DotNetCore.WindowsService.Interfaces;
using DasMulli.Win32.ServiceUtils;

namespace PeterKottas.DotNetCore.WindowsService
{
Expand All @@ -30,7 +31,9 @@ public HostConfiguration()

public string DisplayName { get; set; }

public bool StartImmediately { get; set; }
public bool StartImmediately { get; set; } = true;

public Win32ServiceCredentials DefaultCred { get; set; } = Win32ServiceCredentials.LocalSystem;

public SERVICE Service { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<Version>2.0.2</Version>
<AssemblyVersion>2.0.2.0</AssemblyVersion>
<FileVersion>2.0.2.0</FileVersion>
<Version>2.0.3</Version>
<AssemblyVersion>2.0.3.0</AssemblyVersion>
<FileVersion>2.0.3.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DasMulli.Win32.ServiceUtils" Version="1.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>PeterKottas.DotNetCore.WindowsService</id>
<title>PeterKottas.DotNetCore.WindowsService</title>
<version>2.0.2</version>
<version>2.0.3</version>
<authors>Peter Kottas</authors>
<description>Easiest to use library that allows one to host .net core as windows services there is.</description>
<summary>.NET Core Windows service</summary>
Expand Down
28 changes: 26 additions & 2 deletions Source/PeterKottas.DotNetCore.WindowsService/ServiceRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,31 @@ public static int Run(Action<HostConfigurator<SERVICE>> runAction)
});
config.AddParameter(new CmdArgParam()
{
Key = "startimmediately",
Key = "built-in-account",
Description = "Password for the service account",
Value = val =>
{
switch (val.ToLower())
{
case "localsystem":
innerConfig.DefaultCred = Win32ServiceCredentials.LocalSystem;
break;
case "localservice":
innerConfig.DefaultCred = Win32ServiceCredentials.LocalService;
break;
case "networkservice":
innerConfig.DefaultCred = Win32ServiceCredentials.NetworkService;
break;
default:
innerConfig.DefaultCred = Win32ServiceCredentials.LocalSystem;
break;
}

}
});
config.AddParameter(new CmdArgParam()
{
Key = "start-immediately",
Description = "Start the service immediately when installing.",
Value = val =>
{
Expand Down Expand Up @@ -201,7 +225,7 @@ private static string GetServiceCommand(List<string> extraArguments)

private static void Install(HostConfiguration<SERVICE> config, ServiceController sc, int counter = 0)
{
Win32ServiceCredentials cred = Win32ServiceCredentials.LocalSystem;
Win32ServiceCredentials cred = config.DefaultCred;
if (!string.IsNullOrEmpty(config.Username))
{
cred = new Win32ServiceCredentials(config.Username, config.Password);
Expand Down
1 change: 1 addition & 0 deletions Source/PeterKottas.DotNetCore.WindowsService/pack.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nuget pack PeterKottas.DotNetCore.WindowsService.nuspec

0 comments on commit 3d10ad2

Please sign in to comment.