如何在安装时自动允许我的服务与桌面交互?

发布于 2024-07-13 18:01:10 字数 524 浏览 15 评论 0原文

我构建了一个 Windows 服务,正在通过 .NET 2.0 的 installutil /i 命令安装该服务。 它使用以下帐户和密码安装服务:

NT AUTHORITY\LocalService

当我使用 net start 运行我的服务时,我得到

Error 5: Access Denied

要删除它,我必须打开 services .msc 并从属性中提供服务

Logon As -> Local System Account
         -> Allow Service to interact with desktop.

我可以将整个“点击”业务放入本机 .NET C# 代码或 WMI 或其他批处理脚本中吗? 无论如何我都会使用批处理脚本,所以两者都可以。

I have a Windows service built which is being installed by .NET 2.0's installutil /i command. It installs the service as with the following account, with a password:

NT AUTHORITY\LocalService

When I run my service with net start <serviceName>, I get

Error 5: Access Denied

To remove it I've had to open up services.msc and from the Properties give the service

Logon As -> Local System Account
         -> Allow Service to interact with desktop.

Can I put this whole “clicky” business into code which is either native .NET C# code or WMI or some other Batch script? I'll be using a batch script anyways so either is fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2024-07-20 18:01:10

找到了答案,非常感谢我给予充分信任的以下网页。

链接文本

这是我的解决方案,只需根据需要更改您的服务名称即可。 将其放入 C# 控制台应用程序中并运行它:)

static void Main(string[] args)
{
    string serviceName = "SERVICE_NAME_HERE"; 
    string objPath = string.Format("Win32_Service.Name='{0}'", serviceName);
    using (ManagementObject service = new ManagementObject(new ManagementPath(objPath)))
    {
        object[] wmiParams = new object[11];
        wmiParams[6] = "LocalSystem";
        wmiParams[7] = "";
        service.InvokeMethod("Change", wmiParams);
    }
}

}

Figured out an Answer, thanks very much to the following Webpage to which I give full credit.

link text

Here's the Solution I have, just change your service name as needed. Throw it in a C# Console App and run it :)

static void Main(string[] args)
{
    string serviceName = "SERVICE_NAME_HERE"; 
    string objPath = string.Format("Win32_Service.Name='{0}'", serviceName);
    using (ManagementObject service = new ManagementObject(new ManagementPath(objPath)))
    {
        object[] wmiParams = new object[11];
        wmiParams[6] = "LocalSystem";
        wmiParams[7] = "";
        service.InvokeMethod("Change", wmiParams);
    }
}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文