.net建立並安裝windows案例

來源:互聯網
上載者:User

標籤:ar   io   使用   sp   on   art   bs   cti   amp   

1. 建立windows服務【引用博文】:

1. 將這個服務程式切換到設計檢視
2. 右擊設計檢視選擇“添加安裝程式”
3. 切換到剛被添加的ProjectInstaller的設計檢視
4. 設定serviceInstaller1組件的屬性:
1) ServiceName = My Sample Service
2) StartType = Automatic
5. 設定serviceProcessInstaller1組件的屬性
1) Account = LocalSystem
6. 產生解決方案

注意:嘗試同時啟用多服務,個人測試並沒有成功!

ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new NFSMainService()
};
ServiceBase.Run(ServicesToRun);

ServiceBase[] 數組中放多個服務時,只能運行第一個,看了許多博文但未能解決,不過我們可以將多個服務以類的形式放到一個服務中。

2.安裝服務有兩種方法:

1.通過InstallUtil程式去安裝:通過開啟Visual Studio .NET命令,格式:路徑 InstallUtil.exe MyWindowsService.exe;

卸載的話:格式:路徑 InstallUtil.exe MyWindowsService.exe /u

但如果到客戶方部署的話,生產環境未必有Visual Studio .NET命令,這種情況我們可以打包服務,也可以使用cmd命令:

sc create 服務名字 binPath=  E:\Test\WindowsApplication1\WindowsService1\bin\Debug\ WindowsService1.exe,斷行符號;

binPath=後面需要加空格。

卸載:

SC delete 服務名字

.net建立並安裝windows案例

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.