Skip to content

Commit

Permalink
Merge pull request dotnet/corefx#22920 from weshaggard/ServiceBase
Browse files Browse the repository at this point in the history
Add ServiceBase

Commit migrated from dotnet/corefx@bdb9164
  • Loading branch information
weshaggard authored Aug 4, 2017
2 parents a3088c7 + 64a077f commit b65eee6
Show file tree
Hide file tree
Showing 40 changed files with 2,352 additions and 878 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool ChangeServiceConfig2(IntPtr serviceHandle, uint infoLevel, ref SERVICE_DESCRIPTION serviceDesc);

[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool ChangeServiceConfig2(IntPtr serviceHandle, uint infoLevel, ref SERVICE_DELAYED_AUTOSTART_INFO serviceDesc);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
public extern static IntPtr CreateService(IntPtr databaseHandle, string serviceName, string displayName, int access, int serviceType,
int startType, int errorControl, string binaryPath, string loadOrderGroup, IntPtr pTagId, string dependencies,
string servicesStartName, string password);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
public extern static bool DeleteService(IntPtr serviceHandle);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
public extern static IntPtr RegisterServiceCtrlHandler(string serviceName, Delegate callback);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
public extern static IntPtr RegisterServiceCtrlHandlerEx(string serviceName, Delegate callback, IntPtr userData);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SERVICE_DELAYED_AUTOSTART_INFO
{
public bool fDelayedAutostart;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SERVICE_DESCRIPTION
{
public IntPtr description;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
[StructLayout(LayoutKind.Sequential)]
public class SERVICE_TABLE_ENTRY
{
public IntPtr name;
public Delegate callback;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
public delegate void ServiceMainCallback(int argCount, IntPtr argPointer);
public delegate void ServiceControlCallback(int control);
public delegate int ServiceControlCallbackEx(int control, int eventType, IntPtr eventData, IntPtr eventContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,40 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
internal partial class AcceptOptions
{
internal const int ACCEPT_POWEREVENT = 0x00000040;
internal const int ACCEPT_PAUSE_CONTINUE = 0x00000002;
internal const int ACCEPT_SESSIONCHANGE = 0x00000080;
internal const int ACCEPT_SHUTDOWN = 0x00000004;
internal const int ACCEPT_STOP = 0x00000001;
}

internal partial class ControlOptions
{
internal const int CONTROL_CONTINUE = 0x00000003;
internal const int CONTROL_INTERROGATE = 0x00000004;
internal const int CONTROL_PAUSE = 0x00000002;
internal const int CONTROL_POWEREVENT = 0x0000000D;
internal const int CONTROL_SESSIONCHANGE = 0x0000000E;
internal const int CONTROL_SHUTDOWN = 0x00000005;
internal const int CONTROL_STOP = 0x00000001;
}

internal partial class ServiceConfigOptions
{
internal const int SERVICE_CONFIG_DESCRIPTION = 0x00000001;
internal const int SERVICE_CONFIG_FAILURE_ACTIONS = 0x00000002;
internal const int SERVICE_CONFIG_DELAYED_AUTO_START_INFO = 0x00000003;
}

internal partial class ServiceOptions
{
internal const int SERVICE_QUERY_CONFIG = 0x0001;
Expand All @@ -44,6 +60,7 @@ internal partial class ServiceOptions
SERVICE_INTERROGATE |
SERVICE_USER_DEFINED_CONTROL;

internal const int STANDARD_RIGHTS_DELETE = 0x00010000;
internal const int STANDARD_RIGHTS_REQUIRED = 0x000F0000;
}

Expand All @@ -70,6 +87,30 @@ internal partial class ServiceTypeOptions
SERVICE_TYPE_INTERACTIVE_PROCESS;
}

internal partial class ServiceAccessOptions
{
internal const int ACCESS_TYPE_CHANGE_CONFIG = 0x0002;
internal const int ACCESS_TYPE_ENUMERATE_DEPENDENTS = 0x0008;
internal const int ACCESS_TYPE_INTERROGATE = 0x0080;
internal const int ACCESS_TYPE_PAUSE_CONTINUE = 0x0040;
internal const int ACCESS_TYPE_QUERY_CONFIG = 0x0001;
internal const int ACCESS_TYPE_QUERY_STATUS = 0x0004;
internal const int ACCESS_TYPE_START = 0x0010;
internal const int ACCESS_TYPE_STOP = 0x0020;
internal const int ACCESS_TYPE_USER_DEFINED_CONTROL = 0x0100;
internal const int ACCESS_TYPE_ALL =
ServiceOptions.STANDARD_RIGHTS_REQUIRED |
ACCESS_TYPE_QUERY_CONFIG |
ACCESS_TYPE_CHANGE_CONFIG |
ACCESS_TYPE_QUERY_STATUS |
ACCESS_TYPE_ENUMERATE_DEPENDENTS |
ACCESS_TYPE_START |
ACCESS_TYPE_STOP |
ACCESS_TYPE_PAUSE_CONTINUE |
ACCESS_TYPE_INTERROGATE |
ACCESS_TYPE_USER_DEFINED_CONTROL;
}

internal partial class ServiceStartModes
{
internal const int START_TYPE_BOOT = 0x00000000;
Expand Down Expand Up @@ -104,11 +145,57 @@ internal partial class ServiceControlStatus
internal const int STATE_STOP_PENDING = 0x00000003;
}

internal partial class ServiceStartErrorModes
{
internal const int ERROR_CONTROL_CRITICAL = 0x00000003;
internal const int ERROR_CONTROL_IGNORE = 0x00000000;
internal const int ERROR_CONTROL_NORMAL = 0x00000001;
internal const int ERROR_CONTROL_SEVERE = 0x00000002;
}

internal partial class ServiceControllerOptions
{
internal const int SC_ENUM_PROCESS_INFO = 0;
internal const int SC_MANAGER_CONNECT = 0x0001;
internal const int SC_MANAGER_CREATE_SERVICE = 0x0002;
internal const int SC_MANAGER_ENUMERATE_SERVICE = 0x0004;
internal const int SC_ENUM_PROCESS_INFO = 0;
internal const int SC_MANAGER_LOCK = 0x0008;
internal const int SC_MANAGER_MODIFY_BOOT_CONFIG = 0x0020;
internal const int SC_MANAGER_QUERY_LOCK_STATUS = 0x0010;
internal const int SC_MANAGER_ALL =
ServiceOptions.STANDARD_RIGHTS_REQUIRED |
SC_MANAGER_CONNECT |
SC_MANAGER_CREATE_SERVICE |
SC_MANAGER_ENUMERATE_SERVICE |
SC_MANAGER_LOCK |
SC_MANAGER_QUERY_LOCK_STATUS |
SC_MANAGER_MODIFY_BOOT_CONFIG;
}

internal partial class PowerBroadcastStatus
{
internal const int PBT_APMBATTERYLOW = 0x0009;
internal const int PBT_APMOEMEVENT = 0x000B;
internal const int PBT_APMPOWERSTATUSCHANGE = 0x000A;
internal const int PBT_APMQUERYSUSPEND = 0x0000;
internal const int PBT_APMQUERYSUSPENDFAILED = 0x0002;
internal const int PBT_APMRESUMEAUTOMATIC = 0x0012;
internal const int PBT_APMRESUMECRITICAL = 0x0006;
internal const int PBT_APMRESUMESUSPEND = 0x0007;
internal const int PBT_APMSUSPEND = 0x0004;
}

internal partial class SessionStateChange
{
internal const int WTS_CONSOLE_CONNECT = 0x1;
internal const int WTS_CONSOLE_DISCONNECT = 0x2;
internal const int WTS_REMOTE_CONNECT = 0x3;
internal const int WTS_REMOTE_DISCONNECT = 0x4;
internal const int WTS_SESSION_LOGON = 0x5;
internal const int WTS_SESSION_LOGOFF = 0x6;
internal const int WTS_SESSION_LOCK = 0x7;
internal const int WTS_SESSION_UNLOCK = 0x8;
internal const int WTS_SESSION_REMOTE_CONTROL = 0x9;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe extern static bool SetServiceStatus(IntPtr serviceStatusHandle, SERVICE_STATUS* status);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
public extern static bool StartServiceCtrlDispatcher(IntPtr entry);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Advapi32
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class WTSSESSION_NOTIFICATION
{
public int size;
public int sessionId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ServiceProcess.ServiceController.Tests", "tests\System.ServiceProcess.ServiceController.Tests\System.ServiceProcess.ServiceController.Tests.csproj", "{F7D9984B-02EB-4573-84EF-00FFFBFB872C}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ServiceProcess.ServiceController.TestService", "tests\System.ServiceProcess.ServiceController.TestService\System.ServiceProcess.ServiceController.TestService.csproj", "{E62B874D-1A0D-41BC-8CFC-9E09D0860A77}"
ProjectSection(ProjectDependencies) = postProject
{F4821CB6-91A3-4546-BC4F-E00DBFBDAA05} = {F4821CB6-91A3-4546-BC4F-E00DBFBDAA05}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ServiceProcess.ServiceController.Tests", "tests\System.ServiceProcess.ServiceController.Tests.csproj", "{F7D9984B-02EB-4573-84EF-00FFFBFB872C}"
ProjectSection(ProjectDependencies) = postProject
{F4821CB6-91A3-4546-BC4F-E00DBFBDAA05} = {F4821CB6-91A3-4546-BC4F-E00DBFBDAA05}
EndProjectSection
Expand All @@ -26,10 +31,14 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F7D9984B-02EB-4573-84EF-00FFFBFB872C}.Debug|Any CPU.ActiveCfg = netstandard-Windows_NT-Debug|Any CPU
{F7D9984B-02EB-4573-84EF-00FFFBFB872C}.Debug|Any CPU.Build.0 = netstandard-Windows_NT-Debug|Any CPU
{F7D9984B-02EB-4573-84EF-00FFFBFB872C}.Release|Any CPU.ActiveCfg = netstandard-Windows_NT-Release|Any CPU
{F7D9984B-02EB-4573-84EF-00FFFBFB872C}.Release|Any CPU.Build.0 = netstandard-Windows_NT-Release|Any CPU
{E62B874D-1A0D-41BC-8CFC-9E09D0860A77}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
{E62B874D-1A0D-41BC-8CFC-9E09D0860A77}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{E62B874D-1A0D-41BC-8CFC-9E09D0860A77}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{E62B874D-1A0D-41BC-8CFC-9E09D0860A77}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
{F7D9984B-02EB-4573-84EF-00FFFBFB872C}.Debug|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU
{F7D9984B-02EB-4573-84EF-00FFFBFB872C}.Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
{F7D9984B-02EB-4573-84EF-00FFFBFB872C}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU
{F7D9984B-02EB-4573-84EF-00FFFBFB872C}.Release|Any CPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU
{F4821CB6-91A3-4546-BC4F-E00DBFBDAA05}.Debug|Any CPU.ActiveCfg = netstandard-Windows_NT-Debug|Any CPU
{F4821CB6-91A3-4546-BC4F-E00DBFBDAA05}.Debug|Any CPU.Build.0 = netstandard-Windows_NT-Debug|Any CPU
{F4821CB6-91A3-4546-BC4F-E00DBFBDAA05}.Release|Any CPU.ActiveCfg = netstandard-Windows_NT-Release|Any CPU
Expand All @@ -43,6 +52,7 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E62B874D-1A0D-41BC-8CFC-9E09D0860A77} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
{F7D9984B-02EB-4573-84EF-00FFFBFB872C} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
{F4821CB6-91A3-4546-BC4F-E00DBFBDAA05} = {E107E9C1-E893-4E87-987E-04EF0DCEAEFD}
{8479566D-6FA5-4241-9D66-524BEC4C19BD} = {2E666815-2EDB-464B-9DF6-380BF4789AD4}
Expand Down
Loading

0 comments on commit b65eee6

Please sign in to comment.