c# - 无法在窗口应用程序中打开计算机 '.' 上的窗口服务

标签 c# windows-services windows-applications

我开发了一个窗口应用程序,还创建了一项服务。我在窗口应用程序中使用编码启动服务,但出现无法在计算机上打开窗口服务的错误 '.'

我使用了下面的代码。

ServiceController controller = new ServiceController("SeoMozScheduleService");

if (controller.Status == ServiceControllerStatus.Stopped)
{
    controller.Start();
}

如果我右键单击“应用程序”并单击“以管理员身份运行”,它对我来说工作正常...

最佳答案

要在每次打开应用程序时自动执行此操作,您必须 add a manifest file到您的解决方案,然后将文件中的 requestedExecutionLevel 节点更新为如下所示:

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

但是,如果启用了 UAC,更改此设置将导致系统每次都提示您以管理员身份运行应用程序。

关于c# - 无法在窗口应用程序中打开计算机 '.' 上的窗口服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14501748/

相关文章:

c# - 使用 XAML 进行依赖注入(inject),这可能吗?

Windows 服务中可能使用 C++ SendInput 吗?

windows-applications - Web 身份验证代理总是失败?

windows - 在 WCF 中编写 Windows 服务

c# - 在 Windows 应用程序中处理系统时间更改

c# - 如何将 System.Web 引用添加到 Windows 窗体应用程序

c# - 混淆了? C#中的运算符

c# - 为什么我需要使此方法异步?

c# - SOAP Web服务: many servers, 一个接口(interface)

c# - 使用 .net 启动 Windows 服务开发