CreateService

Linux系统打印机驱动安装 由于Linux系统和Windows系统在操作方法上有较大区别,因此用户在使用Linux系统时,往往不知如何完成一项曾经熟悉的操作。本文以在Linux系统中安装打印机驱动为例,讲解Linux驱动程序安装步骤方法。 阅读详情

CreateService

The CreateService function creates a service object and adds it to the specified service control manager database.

SC_HANDLE CreateService(
  SC_HANDLE hSCManager,
  LPCTSTR lpServiceName,
  LPCTSTR lpDisplayName,
  DWORD dwDesiredAccess,
  DWORD dwServiceType,
  DWORD dwStartType,
  DWORD dwErrorControl,
  LPCTSTR lpBinaryPathName,
  LPCTSTR lpLoadOrderGroup,
  LPDWORD lpdwTagId,
  LPCTSTR lpDependencies,
  LPCTSTR lpServiceStartName,
  LPCTSTR lpPassword
);
Parameters
hSCManager
[in] 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] Pointer to a null-terminated string that specifies 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 back-slash (/) are invalid service name characters.
lpDisplayName
[in] Pointer to a null-terminated string that contains 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] 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] Service types. This parameter can be one of the following values.
ValueMeaning
SERVICE_FILE_SYSTEM_DRIVER
0x00000002
File system driver service.
SERVICE_KERNEL_DRIVER
0x00000001
Driver service.
SERVICE_WIN32_OWN_PROCESS
0x00000010
Service that runs in its own process.
SERVICE_WIN32_SHARE_PROCESS
0x00000020
Service 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
0x00000100
The service can interact with the desktop.

For more information, see Interactive Services.

dwStartType
[in] Service start options. This parameter can be one of the following values.
ValueMeaning
SERVICE_AUTO_START
0x00000002
A service started automatically by the service control manager during system startup.
SERVICE_BOOT_START
0x00000000
A device driver started by the system loader. This value is valid only for driver services.
SERVICE_DEMAND_START
0x00000003
A service started by the service control manager when a process calls the StartService function.
SERVICE_DISABLED
0x00000004
A service that cannot be started. Attempts to start the service result in the error code ERROR_SERVICE_DISABLED.
SERVICE_SYSTEM_START
0x00000001
A device driver started by the IoInitSystem function. This value is valid only for driver services.
dwErrorControl
[in] 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
0x00000003
The startup program logs the error, 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
0x00000000
The startup program logs the error but continues the startup operation.
SERVICE_ERROR_NORMAL
0x00000001
The startup program logs the error and puts up a message box pop-up but continues the startup operation.
SERVICE_ERROR_SEVERE
0x00000002
The startup program logs the error. 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] Pointer to a null-terminated string that contains 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).

lpLoadOrderGroup
[in] Pointer to a null-terminated string that names 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] 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] 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] Pointer to a null-terminated string that specifies 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.

Windows NT:  If the service type is SERVICE_WIN32_SHARE_PROCESS, you must specify the LocalSystem account. On later versions of Windows, 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.

lpPassword
[in] Pointer to a null-terminated string that contains 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.

Passwords are ignored for driver services.

Return Values

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.

Example Code

For an example, see Installing a Service.

Requirements
ClientRequires Windows XP, Windows 2000 Professional, or Windows NT Workstation.
ServerRequires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header

Declared in Winsvc.h; include Windows.h.

Library

Link to Advapi32.lib.

DLLRequires Advapi32.dll.
Unicode

Implemented as CreateServiceW (Unicode) and CreateServiceA (ANSI).

3D打印机组装调试教程之机械结构安装 看到这里,相信你已经准备好组装一台属于自己的3D打印机了。但在你真正动手组装之前,你还需要提前知道一些事情。1、组装3D打印机是需要一些动手能力,但是只要严格按照我的教程组装,每一步都按照要求来做(即使你不理解),你也会最终得到一台精度满足你要求的3D打印机。2、我们需要知道,我们组装的只是一台3D打印机,并不是一台高精度数控机床,所以在组装过程中,我们不可避免的会遇到装配精度问题,比如框架组装之后你发现会有些弯曲,但是这些无伤大雅,对你最后成功得到一台好用的3D打印机影响不大。因此,不必太过强迫症。 阅读详情

相关推荐

Win11安装本地打印机详细教程

通过以上步骤,您应该能够轻松地在Windows 11系统中安装本地打印机。尽管不同品牌和型号的打印机可能在安装过程中略有差异,但总体流程是相似的。如果遇到任何问题,请查阅打印机的用户手册或联系制造商的技术支持以获取帮助。希望本文对您有所帮助,祝您工作顺利!

mmoo_python的博客 1567

CreateService / SC 创建自启动服务

下面的代码创建了一个服务,然后把自己复制到C盘下,通过服务实现开机自启动。 如果要卸载这个服务,只需执行一下命令: sc delete AutoStartServiceDemo // AutoStartServiceDemo.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <windows.h> char lpszServiceName[MAX_PATH]

hambaga的博客 4506

【bat】做个一键连接网络打印机的bat

用bat做个一键连接网络打印机 用途:大部分普通用户来说,并不知道怎么连接网络打印机(共享打印机还好) 好处:用户只需双击bat,输入打印机的IP地址敲下回车即可连接(当然你也可以改成一键连接), 优势:相比点击驱动包的setup还要简单几倍,成功率也高(因为驱动安装包会不能搜索出不同网段的打印机,虽然是网络互通) 代码示例的型号是富士施乐的4475,请读者根据实际情况安装合适的驱动 第三部分,请...

laoxige的博客 1万+

[SC] CreateService 失败 1073: 指定的服务已存在。

以设置MongoDB服务为系统服务,为例: sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB\Server\4.2\mongod.cfg\"" DisplayName= "MongoDB" start= "auto" 在创建系统服务时,提示: [SC] CreateService 失败 1

白骨梦儿 1万+

OPENWRT网络打印机TCP/IP共享设置教程 以703N为例

OPENWRT网络打印机TCP/IP共享设置教程以703N为例 前言 最近一台带USB2.0接口的惠普P1106激光打印机使我比较头疼,由于打印机放在家中楼上,没空调,夏天太热,每次抱着电脑上楼打印都大汗淋漓的下来,于是乎,下定决心一定要能让打印机接入家中无线网络,在空调间就可以凉快的打印,迫于生计,于是寻求度娘,发现openwrt路由器可以实现这一功能,手头上正好有一个改装过的OPENWRT

guanfangtao2的专栏 8万+

电脑连接打印机详细步骤指南

通过以上步骤,我们可以轻松地将电脑与打印机连接起来,并实现顺利打印。在连接过程中,我们需要注意驱动程序的兼容性、连接线材的质量以及打印机的定期维护等问题。只有做好了这些准备工作和后续维护工作,我们才能确保打印机始终保持良好的工作状态,为我们的办公生活提供更加便捷的服务。希望本文能够帮助大家更好地理解和掌握电脑连接打印机的操作步骤,享受更加高效的办公体验。

nntxthml的博客 2128

关于CreateService的一个大问题:权限问题

CreateService的最后两个参数是该服务从属的帐号(用户名,密码)。如果用null填的话,就会用默认帐号 LocalSystem。此帐号有很大的访问限制,在这个帐号下的服务程序不能访问其他帐号下的很多东西。而且在此帐号内生成的共享对象(shared object),其他帐号下的应用程序也不能访问(比如,我用administrator登入系统的,但是服务的帐号却是LocalSystem,则在

mac_forward的专栏 3760

Win11打印机状态错误全面解决方案

Win11打印机状态错误可能由多种原因引起,包括系统配置、服务状态、驱动程序、物理连接以及打印机本身的问题。通过上述五种方法的逐一排查与修复,大多数打印机状态错误都能得到有效解决。希望本文能够为广大Win11用户提供实用的帮助,让打印机重新回归正常工作状态,助力高效办公。

nntxthml的博客 3313

Win11共享打印机无法连接全攻略

共享打印机无法连接的问题可能由多种原因引起,包括注册表设置错误、防火墙阻挡、驱动程序过时等。通过本文提供的解决方法,大多数用户应该能够成功解决这一问题。定期更新打印机驱动程序和操作系统补丁。检查并优化防火墙设置,确保共享打印机的相关端口和协议畅通无阻。定期备份关键系统文件,以防万一需要恢复。保持良好的网络环境和设备维护习惯,确保网络连接的稳定性和设备的正常工作。总之,共享打印机无法连接的问题虽然令人头疼,但只要掌握了正确的解决方法,就能轻松应对。

mmoo_python的博客 3689

如何解决打印机暂停无法继续的问题?这里提供了几个方法

如何解决打印机暂停无法继续的问题?这里提供了几个方法。

wyxtx的博客 2708

Win11找不到打印机解决方法详解

Win11找不到打印机的问题可能由多种因素引起,包括网络配置不当、驱动问题、系统设置错误等。通过上述步骤,用户可以系统地检查和解决这些问题。建议在进行任何更改前,先备份重要数据和系统配置,以防万一。此外,保持系统和驱动程序的更新也是预防此类问题的重要措施。如果以上方法均无法解决问题,建议联系打印机制造商的技术支持团队,获取更专业的帮助。

mmoo_python的博客 3408

Win10连接打印机提示0x00004005错误代码解决方案

遇到Win10连接打印机提示0x00004005错误代码时,不必过于担心。通过修改Server服务设置、检查网络文件和打印机共享设置以及采取一些附加建议,通常可以解决这个问题。希望本文提供的方法能够帮助用户快速恢复打印机的正常工作,提高办公和学习的效率。如果问题仍然存在,建议联系打印机制造商的技术支持团队或寻求专业的IT服务帮助。

mmoo_python的博客 5290

Win11连接Win7共享打印机详细教程

通过以上步骤,你应该能够成功地在Win11系统中连接并使用Win7共享打印机。这个过程虽然涉及多个步骤,但只要按照本文的指引逐步操作,就能轻松完成。如果在连接过程中遇到任何问题,不妨参考本文提供的常见问题及解决方法,相信总能找到合适的解决方案。希望这篇文章能帮助你顺利连接共享打印机,提高工作效率。

nntxthml的博客 5965

飞鸽网络打印机1.2版保姆级安装教程:局域网打印共享5分钟搞定

本文提供飞鸽网络打印机1.2版的保姆级安装与配置教程。该软件能轻松实现局域网打印共享,用户无需复杂网络知识,只需5分钟即可在多台电脑间搭建高效的私有打印网络。文章详细讲解了软件安装、驱动配置、打印机共享设置及多种打印方式,并附有实用的故障排查指南,是解决小型办公或家庭多设备打印难题的简洁方案。

redis7keeper的博客 1072

打印机脱机状态恢复指南

打印机脱机是一个常见的问题,但通过上述方法,我们可以轻松地解决这一问题。首先,检查打印机的连接状态,确保打印机与电脑之间的连接正常。其次,通过Windows设置取消打印机的脱机状态。如果问题依旧存在,可以检查并更新打印机驱动程序,或者重启打印机和电脑。此外,还可以检查打印机的设置和状态,以及使用专业工具进行诊断。希望本文能够帮助你快速恢复打印机的正常工作,提高你的工作效率。

nntxthml的博客 2081

Win11添加网络共享打印机详细教程

通过本文的介绍,您应该已经掌握了在Windows 11系统中添加网络共享打印机的方法。虽然过程可能有些繁琐,但只要您按照步骤操作并耐心等待,就一定能够成功添加打印机并享受便捷的打印服务。希望本文对您有所帮助!

mmoo_python的博客 2591
上一篇: CloseServiceHandle
下一篇: DeleteService
普通网友
博客等级 码龄22年 1万+粉丝 3156原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址