指定服务的安全上下文,安全上下文定义其登录类型。

命名空间:  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]");
}
}
 

ServiceAccount 枚举的更多相关文章

  1. C# 6 与 .NET Core 1.0 高级编程 - 39 章 Windows 服务(上)

    译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 39 章 Windows 服务(上)),不对的地方欢迎指出与交流. 章节出自<Professional C ...

  2. Swift enum(枚举)使用范例

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

  3. 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)

    建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...

  4. Objective-C枚举的几种定义方式与使用

    假设我们需要表示网络连接状态,可以用下列枚举表示: enum CSConnectionState { CSConnectionStateDisconnected, CSConnectionStateC ...

  5. Help Hanzo (素数筛+区间枚举)

    Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000).     (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...

  6. 枚举:enum

    枚举 所谓枚举就是指定好取值范围,所有内容只能从指定范围取得. 例如,想定义一个color类,他只能有RED,GREEN,BLUE三种植. 使用简单类完成颜色固定取值问题. 1,就是说,一个类只能完成 ...

  7. .NET 基础一步步一幕幕[方法、结构、枚举]

    方法.结构.枚举 方法: 将一堆代码进行重用的一种机制. 语法: [访问修饰符] 返回类型 <方法名>(参数列表){ 方法主体: } 返回值类型:如果不需要写返回值,写void 方法名:P ...

  8. Asp.Net 将枚举类型(enum)绑定到ListControl(DropDownList)控件

    在开发过程中一些状态的表示使用到枚举类型,那么如何将枚举类型直接绑定到ListControl(DropDownList)是本次的主题,废话不多说了,直接代码: 首先看工具类代码: /// <su ...

  9. 用枚举enum替代int常量

    枚举的好处: 1. 类型安全性 2.使用方便性 public class EnumDemo { enum Color{ RED(3),BLUE(5),BLACK(8),YELLOW(13),GREEN ...

随机推荐

  1. 让qq图标在自己的网站上显示方法

    代码如下: <div id="xixi" onmouseover="toBig()" style="top: 260px; left: 5px; ...

  2. mysql配置文件转载

    #BEGIN CONFIG INFO#DESCR: 4GB RAM, 只使用InnoDB, ACID, 少量的连接, 队列负载大#TYPE: SYSTEM#END CONFIG INFO ## 此my ...

  3. c#串口编程时,忽略跨线程检查报错

    1.直接在main_Form_Load的初始化中加 //忽略跨线程检查 // System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls ...

  4. angular.js学习

    1.第一个小例子 <!DOCTYPE html> <html> <body> <div ng-app=""> <p>在输 ...

  5. HDU Today--hdu2112

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. C语言之利用递归将十进制转换为二进制

    #include<stdio.h>#include<stdlib.h>void change2(int num){  if (num != 0)   {   change2(n ...

  7. AsEnumrable和AsQueryable的区别

    http://www.cnblogs.com/jianglan/archive/2011/08/11/2135023.html 在写LINQ语句的时候,往往会看到.AsEnumerable() 和 . ...

  8. requestAnimationFrame动画方法

    一.动画方式 在HTML5/CSS3时代,实现动画的方式有许多种: 你可以用css3的animation和@keyframes: 可以用css3的transition: 还可以用原始的setTimeo ...

  9. shell的数组操作

    #/bin/bash #创建数组方式1 arr[]=hello arr[]=world #创建数组方式2 arr=(hello world) #创建数组方式3 arr=([]=hello []=wor ...

  10. LeetCode_Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...