ServiceAccount 枚举
指定服务的安全上下文,安全上下文定义其登录类型。
命名空间: System.ServiceProcess
程序集: System.ServiceProcess(在 System.ServiceProcess.dll 中)
成员名称 | 说明 | |
---|---|---|
LocalService | 充当本地计算机上非特权用户的帐户,该帐户将匿名凭据提供给所有远程服务器。 | |
LocalSystem | 服务控制管理员使用的帐户,它具有本地计算机上的许多权限并作为网络上的计算机。 | |
NetworkService | 提供广泛的本地特权的帐户,该帐户将计算机的凭据提供给所有远程服务器。 | |
User | 由网络上特定的用户定义的帐户。 如果为 ServiceProcessInstaller.Account 成员指定 User,则会使系统在安装服务时提示输入有效的用户名和密码,除非您为ServiceProcessInstaller 实例的 Username 和 Password 这两个属性设置值。 |
当初始化 ServiceProcessInstaller 以指定要安装的服务的安全上下文时,请使用 ServiceAccount 枚举。 安全上下文指示服务在系统上的特权并指示服务在网络上如何操作(例如,服务是否将计算机的凭据或匿名凭据提供给远程服务器)。 该ServiceAccount 枚举提供一系列特权,以便您可以为任何特定的服务指定正好需要的特权。
LocalSystem 值定义具有高度特权的帐户,但大多数服务不需要这种提高的特权级别。 LocalService 和 NetworkService枚举成员为安全上下文提供较低的特权级别。
![]() |
---|
值 LocalService 和 NetworkService 仅适用于 Windows XP 和 Windows Server 2003 系列。 |
下面的代码示例演示如何通过 ServiceAccount 枚举,使用系统帐户的安全上下文安装新程序。
using System; using System.Collections; using System.Configuration.Install; using System.ServiceProcess; using System.ComponentModel; [RunInstaller(true)] public class MyProjectInstaller : Installer { private ServiceInstaller serviceInstaller1; private ServiceInstaller serviceInstaller2; private ServiceProcessInstaller processInstaller; public MyProjectInstaller() { // Instantiate installers for process and services. processInstaller = new ServiceProcessInstaller(); serviceInstaller1 = new ServiceInstaller(); serviceInstaller2 = new ServiceInstaller(); // The services run under the system account. processInstaller.Account = ServiceAccount.LocalSystem; // The services are started manually. serviceInstaller1.StartType = ServiceStartMode.Manual; serviceInstaller2.StartType = ServiceStartMode.Manual; // ServiceName must equal those on ServiceBase derived classes. serviceInstaller1.ServiceName = "Hello-World Service 1"; serviceInstaller2.ServiceName = "Hello-World Service 2"; // Add installers to collection. Order is not important. Installers.Add(serviceInstaller1); Installers.Add(serviceInstaller2); Installers.Add(processInstaller); } public static void Main() { Console.WriteLine("Usage: InstallUtil.exe [<service>.exe]"); } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人