zoukankan      html  css  js  c++  java
  • 允许与桌面交互[.net Windows服务]

    在Windows服务的安装类ProjectInstaller中加入以下方法:

    protected override void OnCommitted(System.Collections.IDictionary savedState)
            {
                base.OnCommitted(savedState);
                //将服务更改为允许桌面交互模式
                ConnectionOptions coOptions = new ConnectionOptions();
                coOptions.Impersonation = ImpersonationLevel.Impersonate;
                ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions);
                mgmtScope.Connect();
                ManagementObject wmiService;
                wmiService = new ManagementObject("Win32_Service.Name='这里是当前服务名'");
                ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");
                InParam["DesktopInteract"] = true;
                ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null);
            }
  • 相关阅读:
    MUI-页面传参数
    Spring-boot:多模块打包
    PythonDay11
    PythonDay10
    PythonDay09
    PythonDay08
    PythonDay07
    PythonDay06
    PythonDay05
    PythonDay04
  • 原文地址:https://www.cnblogs.com/zcjiang/p/3559220.html
Copyright © 2011-2022 走看看