【问题标题】:Can't start a service by C#无法通过 C# 启动服务
【发布时间】:2023-03-31 01:10:01
【问题描述】:

我在使用 C# 启动服务时遇到问题。我收到此错误消息:

System.ComponentModel.Win32Exception (0x80004005):访问被拒绝。

我怎样才能获得许可?

我的简单代码是:

ServiceController s = new ServiceController("Service1", Environment.MachineName);
try
{
    s.Start();
}
catch (Exception e)
{
    Console.WriteLine(e.InnerException);
}

【问题讨论】:

标签: c# windows-services servicecontroller


【解决方案1】:

就像@LasseVågsætherKarlsen 所说:您的应用程序应该有足够的权限并且应该运行提升。更多信息在这里:https://stackoverflow.com/a/2818776/4367

TL;DR;

将以下内容添加到您的应用程序清单中:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

【讨论】:

    猜你喜欢
    • 2016-04-29
    • 1970-01-01
    • 1970-01-01
    • 2015-10-10
    • 2014-11-08
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多