Local System、Local Service與Network Service

CreateService参数介绍
SC_HANDLE CreateService(

SC_HANDLE hSCManager, //服务控制管理程序维护的登记数据库的句柄,由系统函数OpenSCManager 返回

LPCTSTR lpServiceName, //以NULL 结尾的服务名,用于创建登记数据库中的关键字

LPCTSTR lpDisplayName, //以NULL 结尾的服务名,用于用户界面标识服务

DWORD dwDesiredAccess, //指定服务返回类型

DWORD dwServiceType, //指定服务类型

DWORD dwStartType, //指定何时启动服务

DWORD dwErrorControl, //指定服务启动失败的严重程度

LPCTSTR lpBinaryPathName, //指定服务程序二进制文件的路径

LPCTSTR lpLoadOrderGroup, //指定顺序装入的服务组名

LPDWORD lpdwTagId, //忽略,NULL

LPCTSTR lpDependencies, //指定启动该服务前必须先启动的服务或服务组

LPCTSTR lpServiceStartName, //以NULL 结尾的字符串,指定服务帐号。如是NULL,则表示使用LocalSystem 帐号

LPCTSTR lpPassword //以NULL 结尾的字符串,指定对应的口令。为NULL表示无口令。但使用LocalSystem时填NULL

);

其中dwStartType取值类型如下:
共有五种启动类型。前三种类型是:SERVICE_AUTO_START、SERVICE_DISABLED 和 SERVICE_DEMAND_START。对应的标准启动类型:自动、禁用和手动,通常使用“计算机管理”管理工具中的“服务”进行配置。后两种类型是:SERVICE_BOOT_START 和 SERVICE_SYSTEM_START,通常用于配置加载设备驱动程序的方式。例如,在启动计算机时或启动 Windows 2000 时加载。

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 theSC_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.

Value Meaning
SERVICE_ADAPTER
0x00000004

Reserved.

SERVICE_FILE_SYSTEM_DRIVER
0x00000002

File system driver service.

SERVICE_KERNEL_DRIVER
0x00000001

Driver service.

SERVICE_RECOGNIZER_DRIVER
0x00000008

Reserved.

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.

Value Meaning
SERVICE_INTERACTIVE_PROCESS
0x00000100

The 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.

Value Meaning
SERVICE_AUTO_START
0x00000002

A service started automatically by the service control manager during system startup. For more information, see Automatically Starting Services.

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. For more information, seeStarting Services on Demand.

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]

The severity of the error, and action taken, if this service fails to start. This parameter can be one of the following values.

Value Meaning
SERVICE_ERROR_CRITICAL
0x00000003

The 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
0x00000000

The startup program ignores the error and continues the startup operation.

SERVICE_ERROR_NORMAL
0x00000001

The startup program logs the error in the event log but continues the startup operation.

SERVICE_ERROR_SEVERE
0x00000002

The 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 formDomainName\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:  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 lpPasswordparameter 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 code Description
ERROR_ACCESS_DENIED

The handle to the SCM database does not have the SC_MANAGER_CREATE_SERVICE access right.

ERROR_CIRCULAR_DEPENDENCY

A circular service dependency was specified.

ERROR_DUPLICATE_SERVICE_NAME

The display name already exists in the service control manager database either as a service name or as another display name.

ERROR_INVALID_HANDLE

The handle to the specified service control manager database is invalid.

ERROR_INVALID_NAME

The specified service name is invalid.

ERROR_INVALID_PARAMETER

A parameter that was specified is invalid.

ERROR_INVALID_SERVICE_ACCOUNT

The user account name specified in the lpServiceStartName parameter does not exist.

ERROR_SERVICE_EXISTS

The specified service already exists in this database.

ERROR_SERVICE_MARKED_FOR_DELETE

The specified service already exists in this database and has been marked for deletion.

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 CreateServiceChangeServiceConfig, and ChangeServiceConfig2 is saved as values under this key. The following are examples of values stored for a service.

Value Description
DependOnGroup Load-ordering groups on which this service depends, as specified by lpDependencies.
DependOnService Services on which this service depends, as specified by lpDependencies.
Description Description specified by ChangeServiceConfig2 .
DisplayName Display name specified by lpDisplayName.
ErrorControl Error control specified by dwErrorControl.
FailureActions Failure actions specified by ChangeServiceConfig2 .
Group Load ordering group specified by lpLoadOrderGroup. Note that setting this value can override the setting of the DependOnService value.
ImagePath Name of binary file, as specified by lpBinaryPathName.
ObjectName Account name specified by lpServiceStartName.
Start When to start service, as specified by dwStartType.
Tag Tag identifier specified by lpdwTagId.
Type Service 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 client


Windows XP [desktop apps only]


Minimum supported server


Windows Server 2003 [desktop apps only]


Header

Winsvc.h (include Windows.h)

Library

Advapi32.lib

DLL

Advapi32.dll

Unicode and ANSI names


CreateServiceW (Unicode) and CreateServiceA (ANSI)

See also

ChangeServiceConfig
ChangeServiceConfig2
CloseServiceHandle
ControlService
DeleteService
EnumDependentServices
OpenSCManager
QueryServiceConfig
QueryServiceDynamicInformation
QueryServiceObjectSecurity
QueryServiceStatusEx
Service Accounts Step-by-Step Guide
Service Functions
Service Installation, Removal, and Enumeration
SetServiceObjectSecurity
StartService

Local System、Local Service與Network Service

同事詢問Windows服務執行身分的預設選項:Local System、Local Service、Network Service,權限各有何不同?這問題多年前我彷彿知道答案,如今大腦卻不爭氣地只有殘缺印象,爬文時習之,不亦悅乎。

Local System、Local Service、Network Service都是Windows預先定義的本機帳號,但跟一般帳號不同(LookupAccountName查不到),使用時不需密碼,可用於CreateServiceChangeServiceConfig(密碼隨便給)。

Local System

在本機具備最高權限(使用時務必小心),與BUILTIN\Administrators具備相同權限,可存取本機大部分資源,與遠端主機溝通時則使用該主機電腦帳號(<domain_name>\<computer_name>$) 。做為授權對象時,LocalSystem帳號可寫成NT AUTHORITY\SYSTEM、LocalSystem、<computer name>\LocalSystem。執行時期將使用預設使用者機碼(HKET_USERS\.DEFAULT)。

Local Service

在本機的權限相當於Users群組,目的在減小服務或程序遭入侵的損害範圍,存取遠端資源時使用匿名身分。做為授權對象時,Local Service可寫成NT AUTHORITY\LOCAL SERVICE。Local Service有自已的HKEY_USERS機碼(HKEY_USERS\S-1-5-19)

Network Service

在本機的權限相當於Users群組,旨在控制服務程序遭惡意操控時的損害範圍,對外存取遠端資源時使用該主機電腦帳號(<domain_name>\<computer_name>$)。做為授權對象時,Network Service帳號可寫成NT AUTHORITY\NETWORK SERVICE 。Network Service也有自已的HKEY_USERS機碼(HKEY_USERS\S-1-5-20)

时间: 2024-09-29 17:05:15

Local System、Local Service與Network Service的相关文章

数据库无法访问,用户 NT AUTHORITY/SYSTEM或NT AUTHORITY\NETWORK SERVICE登录失败的解决办法

问题:win7中的在IIS 7.0中,在 Default Web Site 目录下挂一虚拟目录. 在相应的应用程序池 DefaultAppPool 设置标识设置成NetworkService. 但是打开页面后,无法打开登录所请求的数据库,用户登录NT AUTHORITY\NETWORK SERVICE失败. 解决办法: 1.打开sqlserver Management studio,在安全性-登录名 下新建一个登记名NETWORK SERVICE ,设置默认数据库为要访问的数据库. 2.然后选

Residential Gateway System for Home Network Service

Disclosed herein is a Residential Gateway (RG) system for home network service. The RG system receives various supplementary services through a Home Network Serving Node (HNSN) that provides home network service. The system includes an Open Service G

内置系统账户:Local system/Network service/Local Service 区别

LocalSystem   账户 LocalSystem是预设的拥有本机所有权限的本地账户,这个账户跟通常的用户账户没有任何关联,也没有用户名和密码之类的凭证.这个服务账户可以 打开注册表的HKEY_LOCAL_MACHINE/Security键,当LocalSystem访问网络资源时,它是作为计算机的域账户使用的. 举例来说,以LocalSystem账户运行的服务主要有:WindowsUpdate   Client.   Clipbook.Com+.DHCP   Client.Messenge

centOS 7一个解决“network.service: control process exited, code=exited status=1”方法

今天早上2017-08-04,我打开虚拟机,使用远程工具xshell对虚拟机进行连接,我发现连接不上去,然后我ifconfig,发现找不到ens33了,就剩一个本地回环,看来是我的网络出现了问题,然后我查看我的网络状态,发现了如下情况: [[email protected] ~]# systemctl status network.service ● network.service - LSB: Bring up/down networking Loaded: loaded (/etc/rc.d

Job for network.service failed because the control process exited with error code问题

Job for network.service failed because the control process exited with error code问题 因为是克隆的,所以需要重新修改静态IP vim /etc/sysconfig/network-scripts/ifcfg-xxx 修改 BOOTPROTO=static 下方添加 IPADDR=静态IP地址 GATEWAY=默认网关 NETMASK=255.255.255.0 DNS1=114.114.114.114 保存之后执行

用户 &#39;NT AUTHORITY\NETWORK SERVICE&#39; 登录失败。

第一步:把'NT AUTHORITY\NETWORK SERVICE' 添加到Administrator组中 我的电脑-->右键-->管理-->本地用户和组 选择"组"-->双击Administrators-->单击"添加"-->单击"高级"-->单击"立即查找"-->在下面的列表中选择Network Service用户-->两次单击"确定"-->

CentOS7 network.service loaded failed 处理技巧

某一日,用systemctl --failed查看到如下错误信息,但实际上网络是OK的,真奇怪: [[email protected] media]# systemctl --failed UNIT            LOAD   ACTIVE SUB    DESCRIPTION network.service loaded failed failed LSB: Bring up/down networking LOAD   = Reflects whether the unit defi

linux虚拟机出现See &#39;systemctl status network.service&#39; and &#39;journalctl -xn&#39; for details.的原因

博主之前也是突然遇到linux没有eth0网卡,重新cp了写了配置但是也没有用,反而有一个莫名其妙的报错 See 'systemctl status network.service' and 'journalctl -xn' for details. 而且再去读eth0会提示file not found 然后尝试重新添加删除网卡 没法重新发现 突然想到会不会是驱动的原因,想到了这个地方 这个是vmware的一个智能设置,他会根据你的ISO自动给你推荐分类的vmware tools,但是博主的IS

ADFS部署过程中设置network service对证书的读取权限

今儿在部署客户正式环境的ADFS时候遇到一问题,在配置完基于声明的身份验证后通过url访问居然报错了,这干过N回的事怎么会出错了呢,百思不得其解 网页报错如下 系统日志报错如下, 回想过程中的每一步,突然想到这回好像没对证书做什么操作,因为证书是客户买的由他们IT人员导入好了的,我就直接在绑定的时候选择下就行了,所以少了一步操作.通过管理工具点开证书右击所有任务-管理私钥-添加NetWork Service,再次访问就没问题了. 下图取自勇哥的博客