本文實例講述了C#使用windows服務(wù)開啟應(yīng)用程序的方法。分享給大家供大家參考。具體如下:
使用windows服務(wù)開啟應(yīng)用程序,會遇到如下問題
1.使用windows服務(wù)開啟的應(yīng)用程序不會顯示應(yīng)用程序界面
解決方法:當安裝服務(wù)之后,選中服務(wù),點擊屬性->登錄,然后設(shè)置登錄身份為本地系統(tǒng)賬戶,并允許服務(wù)與桌面進行交互
2.使用的是遠程桌面進行查看,不會顯示界面
解決方法:不能直接使用mstsc命令進入遠程桌面,要使用mstsc /v:192.168.1.10 /admin命令 ,這里192.168.1.10 指的是服務(wù)器ip地址
//該函數(shù)是為了windows服務(wù)和桌面交互private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e){ base.OnAfterInstall(e.SavedState); ManagementObject wmiService = null; ManagementBaseObject InParam = null; try { wmiService = new ManagementObject(string.Format("Win32_Service.Name='{0}'", serviceInstaller1.ServiceName)); InParam = wmiService.GetMethodParameters("Change"); InParam["DesktopInteract"] = true; wmiService.InvokeMethod("Change", InParam, null); } finally { if (InParam != null) InParam.Dispose(); if (wmiService != null) wmiService.Dispose(); }}希望本文所述對大家的C#程序設(shè)計有所幫助。
新聞熱點
疑難解答
圖片精選