网站首页  词典首页

请输入您要查询的函数:

 

术语 createservice
释义 CreateService
语法:
C++
SC_HANDLE WINAPI CreateService(
__in SC_HANDLE hSCManager,
__in LPCTSTR lpServiceName,
__in_opt LPCTSTR lpDisplayName,
__in DWORD dwDesiredAccess,
__in DWORD dwServiceType,
__in DWORD dwStartType,
__in DWORD dwErrorControl,
__in_opt LPCTSTR lpBinaryPathName,
__in_opt LPCTSTR lpLoadOrderGroup,
__out_opt LPDWORD lpdwTagId,
__in_opt LPCTSTR lpDependencies,
__in_opt LPCTSTR lpServiceStartName,
__in_opt LPCTSTR lpPassword
);
CreateService函数
创建一个服务对象,并将其添加到指定的服务控制管理数据库。
参数
hSCManager [in]
一个句柄,服务控制管理数据库。这种处理是由OpenSCManager函数返回,并必须有SC_MANAGER_CREATE_SERVICE访问权限。有关更多信息,请参阅服务安全和访问权限。
lpServiceName [in]
这项服务的名称进行安装。字符串的最大长度为256个字符。在服务控制管理数据库保存了字符的大小写,但服务名称比较总是不区分大小写。正斜杠(/)和反斜杠(\\)是无效的服务名称字符。
lpDisplayName [中,可选]
显示名称要使用的用户界面的程序,以确定该服务。此字符串有256个字符的最大长度。该名称是区分在服务控制管理器保存。显示名称比较总是不区分大小写。
dwDesiredAccess [in]
对服务的访问。在给予请求的访问,系统检查用户访问调用进程的令牌。对于一个值的列表,请参阅服务安全和访问权限。
dwServiceType [in]
服务类型。此参数可以是下列值之一。
ValueMeaning
SERVICE_ADAPTER
0x00000004Reserved。
SERVICE_FILE_SYSTEM_DRIVER
0x00000002File系统驱动程序服务。
SERVICE_KERNEL_DRIVER
0x00000001Driver服务。
SERVICE_RECOGNIZER_DRIVER
0x00000008Reserved。
SERVICE_WIN32_OWN_PROCESS
0x00000010Service在其自己的进程中运行。
SERVICE_WIN32_SHARE_PROCESS
0x00000020Service共享一个进程,一个或多个其他服务。有关更多信息,请参阅服务程序。
如果您指定SERVICE_WIN32_OWN_PROCESS或SERVICE_WIN32_SHARE_PROCESS,服务是在LocalSystem帐户的上下文中运行,还可以指定以下值。
ValueMeaning
SERVICE_INTERACTIVE_PROCESS
0x00000100The服务可以与桌面交互。
有关更多信息,请参阅互动服务。
dwStartType [in]
该服务启动选项。此参数可以是下列值之一。
ValueMeaning
SERVICE_AUTO_START
0x00000002A服务启动的服务控制管理器会自动在系统启动。有关更多信息,请参见自动启动服务。
SERVICE_BOOT_START
0x00000000A设备驱动程序开始由系统加载器。此值只适用于驱动程序服务。
SERVICE_DEMAND_START
0x00000003A服务启动的服务控制管理器当进程调用StartService函数。有关更多信息,请参阅启动按需服务。
SERVICE_DISABLED
0x00000004A服务不能启动。尝试启动的错误代码,服务结果ERROR_SERVICE_DISABLED。
SERVICE_SYSTEM_START
0x00000001A设备驱动程序开始的IoInitSystem功能。此值只适用于驱动程序服务。
dwErrorControl [in]
错误的严重性,和采取的行动,如果此服务无法启动。此参数可以是下列值之一。
ValueMeaning
SERVICE_ERROR_CRITICAL
0x00000003The启动程序记录在事件日志中的错误,如果可能的话。如果最后的有效配置正在启动,启动操作失败。否则,在系统重新启动的最后一次正确的配置。
SERVICE_ERROR_IGNORE
0x00000000The启动程序将忽略该错误并继续启动运作。
SERVICE_ERROR_NORMAL
0x00000001The启动程序记录在事件日志中的错误,但仍启动运作。
SERVICE_ERROR_SEVERE
0x00000002The启动程序记录在事件日志中的错误。如果最后的有效配置正在启动,启动行动仍在继续。否则,在系统重新启动与上次已知的有效配置。
lpBinaryPathName [中,可选]
在完全合格的路径服务的二进制文件。如果路径中包含空格,必须引用,它是正确的解释。例如,的“D:\\ \\我的共享\\ \\ myservice.exe”应指定为“\\的”D:\\ \\我的共享\\ \\ myservice.exe \\“”。
路径可以还包括自动启动服务的论点。例如,的“D:\\ \\ myshare \\ \\ myservice.exe arg1 arg2”。这些参数被传递给服务入口点(通常的主要功能)。
如果您指定的另一台计算机上的路径,这个比例必须能够访问由本地计算机的计算机帐户,因为这是安全上下文中远程调用中使用。但是,这项规定允许在远程计算机上的任何潜在漏洞影响到本地计算机。因此,最好使用本地文件。
lpLoadOrderGroup [中,可选]
在下命令的小组,由该服务是其成员负载的名字。指定NULL或空字符串如果服务不属于一组。
启动程序使用负载订购团体加载在指定的顺序相对于其他群体的服务组织。在订购团体负荷名单载于以下注册表值:
HKEY_LOCAL_MACHINE \\系统\\ CurrentControlSet \\控制\\ ServiceGroupOrder
lpdwTagId [指出,可选]
一个变量,它接收标记的值是在lpLoadOrderGroup在参数中指定的组独特的指针。指定NULL如果您不改变现有的标记。
您可以使用命令在命令中指定以下注册表值标记为向量组的负载服务启动标记:
HKEY_LOCAL_MACHINE \\系统\\ CurrentControlSet \\控制\\ GroupOrderList中
标签是唯一的评估,司机的服务,SERVICE_BOOT_START或SERVICE_SYSTEM_START的启动类型。
lpDependencies [中,可选]
一个双空指针结尾的空阵列分隔的服务或订购团体,该系统之前,必须启动此服务的负载名。指定NULL或空字符串,如果服务没有依赖性。上一组依赖意味着,这项服务可以运行,如果至少一个小组的成员后,尝试启动该小组的所有成员运行。
您必须前缀SC_GROUP_IDENTIFIER组名单,以便他们可以区分服务的名字,因为服务和服务组共享相同的名称空间。
lpServiceStartName [中,可选]
该帐户下运行的服务应的名称。如果服务类型是SERVICE_WIN32_OWN_PROCESS,使用域名的形式在一个帐户名\\用户名。该服务进程将身份登录此用户。如果该帐户属于内置域,您可以指定。\\用户名。
如果该参数为NULL,CreateService使用LocalSystem帐户。如果服务类型指定SERVICE_INTERACTIVE_PROCESS,服务必须运行在LocalSystem帐户。
如果此参数为NT AUTHORITY \\本地服务,CreateService使用LocalService帐户。如果该参数为NT AUTHORITY \\是NetworkService,CreateService使用NetworkService帐户。
一个共享进程可以运行任何用户。
如果服务类型是SERVICE_KERNEL_DRIVER或SERVICE_FILE_SYSTEM_DRIVER,名称是驱动程序对象的名称,该系统使用加载设备驱动程序。指定NULL如果驱动程序是使用默认对象的名称由我创建/ O系统。
一个服务可以配置为使用管理的帐户或虚拟帐户。如果该服务被配置为使用托管服务帐户,该名称是管理服务帐户的名称。如果该服务被配置为使用虚拟账户,指定为NT服务名称\\服务。如需有关管理服务帐户和虚拟帐户的详细信息,请参阅由服务帐户的逐步指南。
Windows Server 2008中,Windows Vista中的Windows Server 2003,和Windows XP/2000:托管服务和虚拟帐户帐户不支持,直到Windows 7和Windows Server 2008 R2的。
lpPassword [中,可选]
到帐户名称的lpServiceStartName参数指定的密码。指定一个空字符串如果该帐户没有密码,或者服务的本地服务,是NetworkService,或LocalSystem帐户下运行。有关更多信息,请参阅服务记录表。
如果该帐户的名称由lpServiceStartName参数指定的是一个管理服务帐户或虚拟帐户的名称,该lpPassword参数必须是NULL。
密码被忽略的驱动程序服务。
返回值
如果函数成功,返回值是一个句柄服务。
如果函数失败,返回值为NULL。为了获得更多错误信息,调用GetLastError。
下面的错误代码可以设置由服务控制管理器。其他的错误代码可以设置的注册表由服务控制管理器调用的函数。
返回codeDescription
ERROR_ACCESS_DENIEDThe处理的供应链管理数据库没有SC_MANAGER_CREATE_SERVICE访问权限。
ERROR_CIRCULAR_DEPENDENCYA循环服务依存指定。
ERROR_DUPLICATE_SERVICE_NAMEThe显示名称已存在于服务的控制作为一种服务名称或其他显示名称管理器数据库。
ERROR_INVALID_HANDLEThe处理指定的服务控制管理数据库无效。
ERROR_INVALID_NAMEThe指定的服务名称是无效的。
ERROR_INVALID_PARAMETERA参数被指定无效。
ERROR_INVALID_SERVICE_ACCOUNTThe用户帐户名中指定lpServiceStartName参数不存在。
ERROR_SERVICE_EXISTSThe指定的服务已存在此数据库。
备注
在CreateService函数创建一个服务对象,并安装在服务控制管理数据库建立在以下注册表项与作为服务相同的名称主要有:
HKEY_LOCAL_MACHINE \\系统\\ CurrentControlSet \\服务
通过CreateService,ChangeServiceConfig和ChangeServiceConfig2指定的信息保存为此项下的值。以下是一个服务中存储的值的例子。
ValueDescription
DependOnGroupLoad订购团体在本服务的依赖,如lpDependencies指定。
DependOnServiceServices本服务的依赖,具体由lpDependencies。
DescriptionDescription指定ChangeServiceConfig2。
DisplayNameDisplay名称指定lpDisplayName。
ErrorControlError控制指定dwErrorControl。
由ChangeServiceConfig2指定FailureActionsFailure行动。
GroupLoad订货小组lpLoadOrderGroup指定。请注意,设置这个值可以重写DependOnService值设置。
ImagePathName的二进制文件,如lpBinaryPathName指定。
ObjectNameAccount名称指定lpServiceStartName。
StartWhen启动服务,如dwStartType指定。
TagTag标识符指定的lpdwTagId。
TypeService类型的dwServiceType指定。
安装程序和服务本身可以为特定服务信息的其他子项。
返回的句柄是唯一有效的过程称为CreateService。它可以关闭调用CloseServiceHandle功能。
如果您要创建的服务共享一个进程,避免调用,如与过程PRB:ExitProcess期间的职能范围内的影响。此外,不要卸载您服务的DLL。
实例
有关示例,请参见安装服务。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinsvc.h(头文件:winuser.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
Unicode和ANSI namesCreateServiceW(Unicode)和CreateServiceA(ANSI)的
参见
ChangeServiceConfig
ChangeServiceConfig2
CloseServiceHandle
ControlService
DeleteService
EnumDependentServices
OpenSCManager
QueryServiceConfig
QueryServiceObjectSecurity
QueryServiceStatusEx
Service Accounts Step-by-Step Guide
服务函数
服务的安装,删除和枚举
SetServiceObjectSecurity
StartService
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==CreateService Function
Creates a service object and adds it to the specified service control manager database.
Syntax
C++
SC_HANDLE WINAPI CreateService(
__in SC_HANDLE hSCManager,
__in LPCTSTR lpServiceName,
__in_opt LPCTSTR lpDisplayName,
__in DWORD dwDesiredAccess,
__in DWORD dwServiceType,
__in DWORD dwStartType,
__in DWORD dwErrorControl,
__in_opt LPCTSTR lpBinaryPathName,
__in_opt LPCTSTR lpLoadOrderGroup,
__out_opt LPDWORD lpdwTagId,
__in_opt LPCTSTR lpDependencies,
__in_opt LPCTSTR lpServiceStartName,
__in_opt LPCTSTR lpPassword
);
Parameters
hSCManager [in]
A handle to the service control manager database. This handle is returned by the OpenSCManager function and must have the SC_MANAGER_CREATE_SERVICE access right. For more information, see Service Security and Access Rights .
lpServiceName [in]
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.
lpDisplayName [in, optional]
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.
dwDesiredAccess [in]
The access to the service. Before granting the requested access, the system checks the access token of the calling process. For a list of values, see Service Security and Access Rights .
dwServiceType [in]
The service type. This parameter can be one of the following values.
ValueMeaning
SERVICE_ADAPTER
0x00000004Reserved.
SERVICE_FILE_SYSTEM_DRIVER
0x00000002File system driver service.
SERVICE_KERNEL_DRIVER
0x00000001Driver service.
SERVICE_RECOGNIZER_DRIVER
0x00000008Reserved.
SERVICE_WIN32_OWN_PROCESS
0x00000010Service that runs in its own process.
SERVICE_WIN32_SHARE_PROCESS
0x00000020Service that shares a process with one or more other services. For more information, see Service Programs .

If you specify either SERVICE_WIN32_OWN_PROCESS or SERVICE_WIN32_SHARE_PROCESS, and the service is running in the context of the LocalSystem account , you can also specify the following value.
ValueMeaning
SERVICE_INTERACTIVE_PROCESS
0x00000100The service can interact with the desktop.
For more information, see Interactive Services .

dwStartType [in]
The service start options. This parameter can be one of the following values.
ValueMeaning
SERVICE_AUTO_START
0x00000002A service started automatically by the service control manager during system startup. For more information, see Automatically Starting Services .
SERVICE_BOOT_START
0x00000000A device driver started by the system loader. This value is valid only for driver services.
SERVICE_DEMAND_START
0x00000003A service started by the service control manager when a process calls the StartService function. For more information, see Starting Services on Demand .
SERVICE_DISABLED
0x00000004A service that cannot be started. Attempts to start the service result in the error code ERROR_SERVICE_DISABLED.
SERVICE_SYSTEM_START
0x00000001A device driver started by the IoInitSystem function. This value is valid only for driver services.

dwErrorControl [in]
The severity of the error, and action taken, if this service fails to start. This parameter can be one of the following values.
ValueMeaning
SERVICE_ERROR_CRITICAL
0x00000003The startup program logs the error in the event log, if possible. If the last-known-good configuration is being started, the startup operation fails. Otherwise, the system is restarted with the last-known good configuration.
SERVICE_ERROR_IGNORE
0x00000000The startup program ignores the error and continues the startup operation.
SERVICE_ERROR_NORMAL
0x00000001The startup program logs the error in the event log but continues the startup operation.
SERVICE_ERROR_SEVERE
0x00000002The startup program logs the error in the event log. If the last-known-good configuration is being started, the startup operation continues. Otherwise, the system is restarted with the last-known-good configuration.

lpBinaryPathName [in, optional]
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.
lpLoadOrderGroup [in, optional]
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.
The startup program uses load ordering groups to load groups of services in a specified order with respect to the other groups. The list of load ordering groups is contained in the following registry value:
HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\ServiceGroupOrder
lpdwTagId [out, optional]
A pointer to a variable that receives a tag value that is unique in the group specified in the lpLoadOrderGroup parameter. Specify NULL if you are not changing the existing tag.
You can use a tag for ordering service startup within a load ordering group by specifying a tag order vector in the following registry value:
HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\GroupOrderList
Tags are only evaluated for driver services that have SERVICE_BOOT_START or SERVICE_SYSTEM_START start types.
lpDependencies [in, optional]
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.
You must prefix group names with SC_GROUP_IDENTIFIER so that they can be distinguished from a service name, because services and service groups share the same name space.
lpServiceStartName [in, optional]
The name of the account under which the service should run. If the service type is SERVICE_WIN32_OWN_PROCESS, 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.
If this parameter is NULL, CreateService uses the LocalSystem account . If the service type specifies SERVICE_INTERACTIVE_PROCESS, the service must run in the LocalSystem account.
If this parameter is NT AUTHORITY\\LocalService, CreateService uses the LocalService account . If the parameter is NT AUTHORITY\\NetworkService, CreateService uses the NetworkService account .
A shared process can run as any user.
If the service type is SERVICE_KERNEL_DRIVER or SERVICE_FILE_SYSTEM_DRIVER, the name is the driver object name that the system uses to load the device driver. Specify NULL if the driver is to use a default object name created by the I/O system.
A service can be configured to use a managed account or a virtual account. If the service is configured to use a managed service account, the name is the managed service account name. If the service is configured to use a virtual account, specify the name as NT SERVICE\\ServiceName. For more information about managed service accounts and virtual accounts, see the Service Accounts Step-by-Step Guide .
Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP/2000: Managed service accounts and virtual accounts are not supported until Windows 7 and Windows Server 2008 R2.
lpPassword [in, optional]
The password to the account name specified by the lpServiceStartName parameter. Specify an empty string if the account has no password or if the service runs in the LocalService, NetworkService, or LocalSystem account. For more information, see Service Record List .
If the account name specified by the lpServiceStartName parameter is the name of a managed service account or virtual account name, the lpPassword parameter must be NULL.
Passwords are ignored for driver services.
Return Value
If the function succeeds, the return value is a handle to the service.
If the function fails, the return value is NULL. To get extended error information, call GetLastError .
The following error codes can be set by the service control manager. Other error codes can be set by the registry functions that are called by the service control manager.
Return codeDescription
ERROR_ACCESS_DENIEDThe handle to the SCM database does not have the SC_MANAGER_CREATE_SERVICE access right.
ERROR_CIRCULAR_DEPENDENCYA circular service dependency was specified.
ERROR_DUPLICATE_SERVICE_NAMEThe display name already exists in the service control manager database either as a service name or as another display name.
ERROR_INVALID_HANDLEThe handle to the specified service control manager database is invalid.
ERROR_INVALID_NAMEThe specified service name is invalid.
ERROR_INVALID_PARAMETERA parameter that was specified is invalid.
ERROR_INVALID_SERVICE_ACCOUNTThe user account name specified in the lpServiceStartName parameter does not exist.
ERROR_SERVICE_EXISTSThe specified service already exists in this database.

Remarks
The CreateService function creates a service object and installs it in the service control manager database by creating a key with the same name as the service under the following registry key:
HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services
Information specified by CreateService, ChangeServiceConfig , and ChangeServiceConfig2 is saved as values under this key. The following are examples of values stored for a service.
ValueDescription
DependOnGroupLoad-ordering groups on which this service depends, as specified by lpDependencies.
DependOnServiceServices on which this service depends, as specified by lpDependencies.
DescriptionDescription specified by ChangeServiceConfig2 .
DisplayNameDisplay name specified by lpDisplayName.
ErrorControlError control specified by dwErrorControl.
FailureActionsFailure actions specified by ChangeServiceConfig2 .
GroupLoad ordering group specified by lpLoadOrderGroup. Note that setting this value can override the setting of the DependOnService value.
ImagePathName of binary file, as specified by lpBinaryPathName.
ObjectNameAccount name specified by lpServiceStartName.
StartWhen to start service, as specified by dwStartType.
TagTag identifier specified by lpdwTagId.
TypeService type specified by dwServiceType.

Setup programs and the service itself can create additional subkeys for service-specific information.
The returned handle is only valid for the process that called CreateService. It can be closed by calling the CloseServiceHandle function.
If you are creating services that share a process, avoid calling functions with process-wide effects, such as ExitProcess . In addition, do not unload your service DLL.
Examples
For an example, see Installing a Service .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinsvc.h (include Windows.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
Unicode and ANSI namesCreateServiceW (Unicode) and CreateServiceA (ANSI)
See Also
ChangeServiceConfig
ChangeServiceConfig2
CloseServiceHandle
ControlService
DeleteService
EnumDependentServices
OpenSCManager
QueryServiceConfig
QueryServiceObjectSecurity
QueryServiceStatusEx
Service Accounts Step-by-Step Guide
Service Functions
Service Installation, Removal, and Enumeration
SetServiceObjectSecurity
StartService
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms682450(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 11:28:27