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