|
ServiceHelperCreateService Method |
Creates a service object and adds it to the specified service control manager database.
CreateService function Namespace: Xcalibur.NativeMethods.V2.ServicesAssembly: Xcalibur.NativeMethods.V2 (in Xcalibur.NativeMethods.V2.dll) Version: 1.0.1.0
Syntax [DllImportAttribute("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static IntPtr CreateService(
IntPtr scManager,
string serviceName,
string displayName,
uint desiredAccess,
ServiceTypes serviceType,
ServiceStartTypes startType,
ServiceErrors errorControl,
string binaryPathName,
string loadOrderGroup,
string tagId,
string dependencies,
string serviceStartName,
string password
)
<DllImportAttribute("advapi32.dll", CharSet := CharSet.Auto, SetLastError := true>]
Public Shared Function CreateService (
scManager As IntPtr,
serviceName As String,
displayName As String,
desiredAccess As UInteger,
serviceType As ServiceTypes,
startType As ServiceStartTypes,
errorControl As ServiceErrors,
binaryPathName As String,
loadOrderGroup As String,
tagId As String,
dependencies As String,
serviceStartName As String,
password As String
) As IntPtr
public:
[DllImportAttribute(L"advapi32.dll", CharSet = CharSet::Auto, SetLastError = true)]
static IntPtr CreateService(
IntPtr scManager,
String^ serviceName,
String^ displayName,
unsigned int desiredAccess,
ServiceTypes serviceType,
ServiceStartTypes startType,
ServiceErrors errorControl,
String^ binaryPathName,
String^ loadOrderGroup,
String^ tagId,
String^ dependencies,
String^ serviceStartName,
String^ password
)
[<DllImportAttribute("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)>]
static member CreateService :
scManager : IntPtr *
serviceName : string *
displayName : string *
desiredAccess : uint32 *
serviceType : ServiceTypes *
startType : ServiceStartTypes *
errorControl : ServiceErrors *
binaryPathName : string *
loadOrderGroup : string *
tagId : string *
dependencies : string *
serviceStartName : string *
password : string -> IntPtr
Parameters
- scManager IntPtr
- A handle to the service control manager database.
- serviceName String
- The name of the service to install. The maximum string length is
256 characters. The service control manager database preserves the case of the characters,
but service name comparisons are always case insensitive. Forward-slash (/) and backslash
(\) are not valid service name characters.
- displayName String
- The display name to be used by user interface programs to
identify the service. This string has a maximum length of 256 characters. The name is
case-preserved in the service control manager. Display name comparisons are always
case-insensitive.
- desiredAccess UInt32
- The access to the service. Before granting the requested
access, the system checks the access token of the calling process
- serviceType ServiceTypes
- Type of the service.
- startType ServiceStartTypes
- The service start options.
- errorControl ServiceErrors
- The severity of the error, and action taken, if this service
fails to start.
- binaryPathName String
- The fully qualified path to the service binary file. If the
path contains a space, it must be quoted so that it is correctly interpreted. For example,
"d:\\my share\\myservice.exe" should be specified as "\"d:\\my share\\myservice.exe\"".
The path can also include arguments for an auto-start service.For example,
"d:\\myshare\\myservice.exe arg1 arg2". These arguments are passed to the service entry
point (typically the main function).
If you specify a path on another computer, the share must be accessible by the computer
account of the local computer because this is the security context used in the remote call.
However, this requirement allows any potential vulnerabilities in the remote computer to
affect the local computer. Therefore, it is best to use a local file.
- loadOrderGroup String
- The names of the load ordering group of which this service is
a member. Specify NULL or an empty string if the service does not belong to a group.
- tagId String
- A pointer to a variable that receives a tag value that is unique in the
group specified in the loadOrderGroup parameter. Specify NULL if you are not changing the
existing tag.
- dependencies String
- A pointer to a double null-terminated array of null-separated
names of services or load ordering groups that the system must start before this service.
Specify NULL or an empty string if the service has no dependencies. Dependency on a group
means that this service can run if at least one member of the group is running after an
attempt to start all members of the group.
- serviceStartName String
- The name of the account under which the service should run.
If the service type is , use an account name
in the form DomainName\UserName. The service process will be logged on as this user. If the
account belongs to the built-in domain, you can specify .\UserName.
- password String
- The password to the account name specified by the serviceStartName
parameter. Specify an empty string if the account has no password or if the service runs in
the LocalService, NetworkService, or LocalSystem account.
Return Value
IntPtrIf the function fails, the return value is zero. To get extended error
information, call .
See Also