C#中windows 服务与桌面交互

    技术2022-11-25  7

     

    服务安装后事件 这样就可以交互了 private void serviceInstaller1_AfterInstall( object sender, InstallEventArgs e) { ManagementBaseObject inPar = null ; ManagementClass mc = new ManagementClass( " Win32_Service " ); foreach (ManagementObject mo in mc.GetInstances()) { if (mo[ " Name " ].ToString() == "服务名 " ) { inPar = mo.GetMethodParameters( " Change " ); inPar[ " DesktopInteract " ] = true ; mo.InvokeMethod( " Change " , inPar, null ); } } } ============================================================= 或者onstart的时候修改注册表[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/你的服务名]     "Type"=dword:00000010     key value+256     比如现在00000010是16+256=272     16进制就是00000110  

    最新回复(0)