Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何以管理员权限启动Windows服务_C#_.net_Sql Server_Windows Services - Fatal编程技术网

C# 如何以管理员权限启动Windows服务

C# 如何以管理员权限启动Windows服务,c#,.net,sql-server,windows-services,C#,.net,Sql Server,Windows Services,我有自己的应用程序服务器,它是windows服务,它与sql server通信,在某些情况下sql server服务停止,因此我通过此代码声明 ServiceController sc = new ServiceController("MSSQL$SQLEXPRESS"); sc.Start(); sc.WaitForStatus(ServiceControllerStatus.Running); 但启动服务需要管理员权限我如何以管理员身份启动窗口服务我只需在app.manifest文件中添加

我有自己的应用程序服务器,它是windows服务,它与sql server通信,在某些情况下sql server服务停止,因此我通过此代码声明

ServiceController sc = new ServiceController("MSSQL$SQLEXPRESS");
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running);

但启动服务需要管理员权限我如何以管理员身份启动窗口服务我只需在app.manifest文件中添加此标记

它是有效的…

让我们将所有内容分解成步骤

  • 将文件“应用程序清单文件”添加到根目录
  • 选择项目属性
  • 在“应用程序”选项卡“资源组查找清单”字段中
  • 粘贴新的清单文件名。可能是“app.manifest”
  • 用此信息填充文件
  • 根据您的情况,所有信息可能会略有不同。

    
    
    您是否尝试以管理员身份运行启动服务的应用程序?但这两个应用程序都是windows服务。如何以管理员身份运行windows服务。我只需在app.manifest文件中添加此标记即可…然后将其作为答案写入,这样这个问题就不会被视为未回答。
    <?xml version="1.0" encoding="utf-8"?>
    <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
          <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
            <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
          </requestedPrivileges>
          <applicationRequestMinimum>
            <defaultAssemblyRequest permissionSetReference="Custom" />
            <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
          </applicationRequestMinimum>
        </security>
      </trustInfo>
    </asmv1:assembly>