標籤:des style blog http color 使用
windows 服務預設位於windows 7 的session 0 中,傳統型程式位於session 1中,預設情況下二者無法互動
使用如下方法可以使在服務安裝完成之後預設勾選“屬性”->“登入”->“允許服務與案頭互動。
1 private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e) 2 { 3 4 SetServiceDesktopInsteract("你的服務名稱"); 5 System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(); 6 sc.ServiceName = "你的服務名稱"; 7 sc.Start(); 8 } 9 10 private void SetServiceDesktopInsteract(string serviceName)11 {12 System.Management.ManagementObject wmiService = new System.Management.ManagementObject(string.Format("Win32_Service.Name=‘{0}‘", serviceName));13 System.Management.ManagementBaseObject changeMethod = wmiService.GetMethodParameters("Change");14 changeMethod["DesktopInteract"] = true;15 System.Management.ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", changeMethod, null);16 }
查看代碼
僅作備忘