Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than advapi32, prefix the name with the module name and a period.
<DllImport("advapi32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function CreateService(ByVal hSCManager As IntPtr, ByVal serviceName As String, _
ByVal displayName As String, ByVal desiredAccess As Int32, ByVal serviceType As Int32, _
ByVal startType As Int32, ByVal errorcontrol As Int32, ByVal binaryPathName As String, _
ByVal loadOrderGroup As String, ByVal TagBY As Int32, ByVal dependencides As String, _
ByVal serviceStartName As String, ByVal password As String) As IntPtr
User-Defined Types:
None.
C# User-Defined Types:
[Flags]
public enum SERVICE_ACCESS : uint
{
STANDARD_RIGHTS_REQUIRED = 0xF0000,
/// <summary>
/// Required to call the QueryServiceConfig and
/// QueryServiceConfig2 functions to query the service configuration.
/// </summary>
SERVICE_QUERY_CONFIG = 0x00001,
/// <summary>
/// Required to call the ChangeServiceConfig or ChangeServiceConfig2 function
/// to change the service configuration. Because this grants the caller
/// the right to change the executable file that the system runs,
/// it should be granted only to administrators.
/// </summary>
SERVICE_CHANGE_CONFIG = 0x00002,
/// <summary>
/// Required to call the QueryServiceStatusEx function to ask the service
/// control manager about the status of the service.
/// </summary>
SERVICE_QUERY_STATUS = 0x00004,
/// <summary>
/// Required to call the EnumDependentServices function to enumerate all
/// the services dependent on the service.
/// </summary>
SERVICE_ENUMERATE_DEPENDENTS = 0x00008,
/// <summary>
/// Required to call the StartService function to start the service.
/// </summary>
SERVICE_START = 0x00010,
/// <summary>
/// Required to call the ControlService function to stop the service.
/// </summary>
SERVICE_STOP = 0x00020,
/// <summary>
/// Required to call the ControlService function to pause or continue
/// the service.
/// </summary>
SERVICE_PAUSE_CONTINUE = 0x00040,
/// <summary>
/// Required to call the EnumDependentServices function to enumerate all
/// the services dependent on the service.
/// </summary>
SERVICE_INTERROGATE = 0x00080,
/// <summary>
/// Required to call the ControlService function to specify a user-defined
/// control code.
/// </summary>
SERVICE_USER_DEFINED_CONTROL = 0x00100,
/// <summary>
/// Includes STANDARD_RIGHTS_REQUIRED in addition to all access rights in this table.
/// </summary>
SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED |
SERVICE_QUERY_CONFIG |
SERVICE_CHANGE_CONFIG |
SERVICE_QUERY_STATUS |
SERVICE_ENUMERATE_DEPENDENTS |
SERVICE_START |
SERVICE_STOP |
SERVICE_PAUSE_CONTINUE |
SERVICE_INTERROGATE |
SERVICE_USER_DEFINED_CONTROL)
}
/// <summary>
/// Service that runs in its own process.
/// </summary>
SERVICE_WIN32_OWN_PROCESS = 0x00000010,
/// <summary>
/// Service that shares a process with one or more other services.
/// </summary>
SERVICE_WIN32_SHARE_PROCESS = 0x00000020,
/// <summary>
/// The service can interact with the desktop.
/// </summary>
SERVICE_INTERACTIVE_PROCESS = 0x00000100,
}
Notes:
The 4th parameter from the end, TagBY, should - accordig to the API documention, be a ByRef parameter. Unfortunately, the call only works if the parameter is ByVal.
lpDependencies, if not null, must be a series of strings concatenated with the null character as a delimiter, including a trailing one.
Tips & Tricks:
Please add some!
Sample Code:
Dim scHandle As IntPtr = OpenSCManager(Nothing, Nothing, SC_MANAGER_ALL_ACCESS)
Dim serviceName As String = "AAATestService"
Dim displayName As String = "AAATestDisplayName"
If OpenFileDialog1.ShowDialog() <> DialogResult.OK Then
MsgBox("aborting")
End If
Dim pathName As String = Chr(34) & OpenFileDialog1.FileName & Chr(34)
Dim serviceHandle As IntPtr = CreateService(scHandle, serviceName, displayName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, _
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, pathName, Nothing, 0, Nothing, Nothing, Nothing)
If serviceHandle.Equals(IntPtr.Zero) Then
MsgBox(Marshal.GetLastWin32Error())
End If
ByRef is a VB keyword that specifies a variable to be passed as a parameter BY REFERENCE. In other words, the pointer to the variable is passed and any change to its value made within the function or sub will change its value outside the function/sub.
4/25/2007 3:19:29 AM - anonymous
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).