在windowService用Process.Start()启动程序没有界面-记录
生活随笔
收集整理的這篇文章主要介紹了
在windowService用Process.Start()启动程序没有界面-记录
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文:在windowService用Process.Start()啟動程序沒有界面-記錄 1.在服務程序安裝時編程實現,ProjectInstaller.cs using?System; using?System.Collections; using?System.Collections.Generic; using?System.ComponentModel; using?System.Configuration.Install; //using?System.Linq; using?Microsoft.Win32;?//對注冊表操作一定要引用這個命名空間 namespace?MonitorService { ????[RunInstaller(true)] ????public?partial?class?ProjectInstaller?:?Installer ????{ ????????public?ProjectInstaller() ????????{ ????????????InitializeComponent();???????????? ????????????//this.Context.Parameters["ServerCode"].ToString();?//?讀取安裝時輸入的服務器編號??????????? ????????} ????????private?void?ProjectInstaller_AfterInstall(object?sender,?InstallEventArgs?e) ????????{ ????????????//設置允許服務與桌面交互 ????????????SetServiceTable("MonitorService");???????????? ????????} ????????///?<summary> ????????///?設置允許服務與桌面交互?,修改了注冊表,要重啟系統才能生效 ????????///?</summary> ????????///?<param?name="ServiceName">服務程序名稱</param> ????????private?void?SetServiceTable(string?ServiceName) ????????{ ????????????RegistryKey?rk?=?Registry.LocalMachine; ????????????string?key?=?@"SYSTEM\CurrentControlSet\Services\"?+?ServiceName; ????????????RegistryKey?sub?=?rk.OpenSubKey(key,?true); ????????????int?value?=?(int)sub.GetValue("Type"); ????????????sub.SetValue("Type",?value?|?256); ????????} ????} } 2.注冊表修改 onstart的時候修改注冊表??? ???[HKEY_LOCAL_MACHINE"SYSTEM"CurrentControlSet"Services"你的服務名]??? ???"Type"=dword:00000010??? ???key????value+256??? ???比如現在00000010是16+256=272??? ???16精制就是00000110 ?? 3.SC程序修改,?允許與桌面進行交互 ?在dos命令提示符下輸入: sc?config?MonitorService?type=?interact?type=?own ?回車即可。 可以用批處理的方式實現,把下面代碼保存為?myservice.bat?即可: ?rem?配置服務程序為允許與桌面進行交互方式 @echo?"準備停止服務程序..." sc?stop?MyService @echo?"設置允許與桌面進行交互方式允許" sc?config?MyService?type=?interact?type=?own @echo?"正在重新啟動服務..." sc?start?MyService @echo?"啟動服務成功!" 取消“允許與桌面進行交互” DOS命令提示符下運行下面語句即可: ?sc?config?MyService?type=?own 經測試:1,2?可以選中“允許與桌面進行交互”,但啟動服務的時候,不能彈出應用程序的界面。 ???????????3?可以完美實現所有要求。
在服務的屬性的登錄選項卡中,把允許服務與桌面交互勾選上,再試試。
總結
以上是生活随笔為你收集整理的在windowService用Process.Start()启动程序没有界面-记录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SSM集成
- 下一篇: JavaEE进阶知识学习-----Spr