windows服務開發(一、安裝)

來源:互聯網
上載者:User

最近由於工作需要,寫了一個windows服務程式,有許多經驗,我會陸續寫出來。
請原諒我從安裝談起,因為我一直有一個誤區:只要從System.ServiceProcess.ServiceBase繼承一個類並編譯好就可以用.net提供的命令列程式InstallUtil.exe安裝了。經過嘗試,發現如果僅僅做了這樣的一個類是無法用InstallUtil.exe安裝的,在安裝時會輸出下面的資訊:

D:\>installutil windowsservice2.exe<br />Microsoft (R) .NET Framework Installation utility Version 1.1.4322.573<br />Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.<br />Running a transacted installation.</p><p>Beginning the Install phase of the installation.<br />See the contents of the log file for the d:\windowsservice2.exe assembly's progr<br />ess.<br />The file is located at d:\windowsservice2.InstallLog.<br />Installing assembly 'd:\windowsservice2.exe'.<br />Affected parameters are:<br /> assemblypath = d:\windowsservice2.exe<br /> logfile = d:\windowsservice2.InstallLog<br />No public installers with the RunInstallerAttribute.Yes attribute could be found<br /> in the d:\windowsservice2.exe assembly.</p><p>The Install phase completed successfully, and the Commit phase is beginning.<br />See the contents of the log file for the d:\windowsservice2.exe assembly's progr<br />ess.<br />The file is located at d:\windowsservice2.InstallLog.<br />Committing assembly 'd:\windowsservice2.exe'.<br />Affected parameters are:<br /> assemblypath = d:\windowsservice2.exe<br /> logfile = d:\windowsservice2.InstallLog<br />No public installers with the RunInstallerAttribute.Yes attribute could be found<br /> in the d:\windowsservice2.exe assembly.<br />Remove InstallState file because there are no installers.</p><p>The Commit phase completed successfully.</p><p>The transacted install has completed.
這是因為installUtil.exe會用反射的方法去尋找所有把RunInstallerAttribute設定為true的System.Configuration.Install.Installer類型,並執行上面的Install方法,當找不到的時候,安裝就失敗了。
所以我們必須要寫一個從Installer類繼承的類來滿足installUtil.exe的要求。

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.