建立Windows服務簡單流程

2022-01-17 02:31:25 字數 1609 閱讀 6159

1.首先開啟vs2010(或者其他版本),建立windows服務專案

2.建立完成後切換到**檢視,**中預設有onstart和onstop方法執行服務開啟和服務停止執行的操作,下面**是詳細解釋:

注意選擇的是系統時間,不是winform中的時間。

using system;

using system.io;

usingsystem.serviceprocess;

using system.text;

usingsystem.timers;

namespacetestservice

protected override voidonstart(string args)

protected override void onstop()

protected override void onpause()

protected override void oncontinue()

protected override void onshutdown()

private void startdosomething()

private void writesomething(objectsource, system.timers.elapsedeventargs e)

catch

finally}}

}}3.然後切換到設計檢視,右鍵點選下圖中圈選的「新增安裝程式

4.選中下圖第乙個控制項,點選f4,右邊切換到屬性檢視;更改屬性檢視中的account屬性為localservice(本地服務)

(automatic)或禁用(disabled)

6.編譯專案,然後win+r輸入cmd進入命令視窗。去對應.net版本下的目錄中找到installutil.exe,我專案採用的是 .net 4.0,故路徑為c:\windows\microsoft.net\framework\v4.0.30319

7.installutil.exe對應.net版本目錄圖,如下

8.然後win+r輸入cmd進入命令視窗。

9.方法刪除服務:直接進行登錄檔編輯            開啟登錄檔編輯器,找到下面的鍵值:

hkey_local_machine\system\currentcontrolset\services        一般服務會以相同的名字在這裡顯示乙個主健,直接刪除相關的鍵值便可。

建立簡單的Windows服務 專案

初始化的程式並執行程式 using system using system.collections.generic using system.componentmodel using system.data using system.diagnostics using system.linq usi...

windows服務建立

以下是安裝命令 啟動服務命令 停止服務命令 解除安裝服務命令 安裝命令 c windowservice installutil.exe c windowservice organizclientsocketservice.exe 啟動服務命令 net start 搜才organiz客戶端資料同步服務...

建立乙個簡單的windows 服務

此服務主要用於開啟服務後定時往資料庫中插入資料,直到關閉服務 1.建立乙個windows service 專案 2.新增乙個service業務功能,用乙個計時器 timer 定時往資料庫中插入記錄 此處需要注意,在initializecomponent方法中,需要將 private system.w...