2010-08-03 64 views
0

我在我的本地PC上創建一個簡單的Windows服務和下面的代碼添加到它安裝Windows服務提供了一個錯誤

Protected Overrides Sub OnStart(ByVal args() As String) 
    Const iTIME_INTERVAL As Integer = 60000  ' 60 seconds. 
    Dim oTimer As System.Threading.Timer 

    System.IO.File.AppendAllText("C:\AuthorLog.txt", _ 
     "AuthorLogService has been started at " & Now.ToString()) 

    Dim tDelegate As Threading.TimerCallback = AddressOf EventAction 
    oTimer = New System.Threading.Timer(tDelegate, Me, 0, iTIME_INTERVAL) 
End Sub 

Protected Overrides Sub OnStop() 

End Sub 


Public Sub EventAction(ByVal sender As Object) 
    System.IO.File.AppendAllText("C:\AuthorLog.txt", _ 
     "AuthorLogService fires EventAction at " & Now.ToString()) 
End Sub 

接下來,我添加了一個安裝項目該解決方案,並添加自定義操作(通過雙點擊應用文件夾,然後點擊添加輸出文件夾,然後從對話框中選擇主要輸出)解決方案建立良好,但我有2個問題。

1)我每次安裝服務,都要求我輸入用戶名,密碼和確認密碼;我想知道是否有至少在本地運行時擺脫它。我嘗試設置帳戶類型爲用戶,本地服務,本地系統等,但它不斷彈出。

2)一旦我輸入憑據(隨機),我收到一個錯誤「沒有帳戶名稱和安全ID之間的映射已完成」。

請幫我出

回答

2

1:你可以讓你的服務被selfinstalling爲this CodeProject上的文章,然後就在你想使用的ServiceProcessInstaller的用戶名/密碼發送。

2:嘗試以不同格式輸入憑據。如果您正在使用「。\ user」,請嘗試寫入「computer \ user」,反之亦然。

+0

使用'installutil.exe'在服務器上安裝服務,我實際上必須使用'。\ user'選項來替代'domain \ user',我認爲這是正確的選擇。 – Chau 2011-11-04 15:03:15