silanos_1

Analytics

ad silanors2

2011年1月7日 星期五

[Windows Service]如何 建立/安裝/移除Windows Service專案(How to build / install / remove Windows Service Project)


問題

如何 建立/安裝/移除Windows Service專案



解決方法

當我們程式不需要人為操作,而是需要排程/定期做某些定事情時,就很適合建立Windows Service Project來開發自己所需要的程式
1.建立一個新的Windows Service Project
1
2
2.撰寫程式碼
image
3.產生安裝程式
  1. Service1.cs右鍵加入安裝程式
  2. 會建立ProjectInstaller.cs
  3. 點serviceProcessInstaller1=>找屬性Account=>選LocalSystem
  4. 點serviceInstaller1=>找屬性ServiceName=>命名"SERVICE名稱"
image
4.建置專案
5.安裝Windows Service程式
  1. 安裝時系統Path多加 C:\Windows\Microsoft.NET\Framework\v2.0.50727\指向installutil.exe(.NetFramework1.1則須更改到C:\Windows\Microsoft.NET\Framework\v1.xxx的資料夾)
image
  1. 啟動DOS
  2. DOS指令位址指向 建置後的程式路徑
  3. 鍵入 installutil "程式名稱.exe"=>進行安裝
或用C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe "程式位置+名稱.exe"
image
6.移除Windows Service程式
鍵入installutil /U "程式名稱.exe"=>進行反安裝
image
7.批次檔安裝或移除Windows Service
批次檔安裝
@echo on
c:
cd \Inetpub\WindowsService1
REM Register Service
pause
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe WindowsService1.exe
pause
批次檔移除
@echo on
c:
cd \Inetpub\WindowsService1
REM Register Service
pause
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe /u WindowsService1.exe
pause

沒有留言:

as silanors3

熱門文章

bloggerads