C#使用windows服務(wù)開(kāi)啟應(yīng)用程序的方法
本文實(shí)例講述了C#使用windows服務(wù)開(kāi)啟應(yīng)用程序的方法。分享給大家供大家參考。具體如下:
使用windows服務(wù)開(kāi)啟應(yīng)用程序,會(huì)遇到如下問(wèn)題
1.使用windows服務(wù)開(kāi)啟的應(yīng)用程序不會(huì)顯示應(yīng)用程序界面
解決方法:當(dāng)安裝服務(wù)之后,選中服務(wù),點(diǎn)擊屬性->登錄,然后設(shè)置登錄身份為本地系統(tǒng)賬戶(hù),并允許服務(wù)與桌面進(jìn)行交互
2.使用的是遠(yuǎn)程桌面進(jìn)行查看,不會(huì)顯示界面
解決方法:不能直接使用mstsc命令進(jìn)入遠(yuǎn)程桌面,要使用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();
}
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
- C#啟動(dòng)windows服務(wù)方法的相關(guān)問(wèn)題分析
- C#啟動(dòng)和停止windows服務(wù)的實(shí)例代碼
- C#編寫(xiě)Windows服務(wù)實(shí)例代碼
- c#創(chuàng)建windows服務(wù)(Windows Services)詳細(xì)步驟
- c#創(chuàng)建windows服務(wù)入門(mén)教程實(shí)例
- C#編寫(xiě)Windows服務(wù)程序詳細(xì)步驟詳解(圖文)
- C#創(chuàng)建Windows服務(wù)的實(shí)現(xiàn)方法
- C#創(chuàng)建Windows服務(wù)與服務(wù)的安裝、卸載
- C#創(chuàng)建Windows Service(Windows 服務(wù))的方法步驟

