2014-02-19 27 views
1

我剛剛建立了一個簡單的Windows服務時遇到麻煩就開始錯誤:2未找到文件 - Windows服務

The Commit phase completed successfully. 

The transacted install has completed. 

M:\MyDocuments\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug>Net start WindowsService1.exe 
System error 2 has occurred. 

The system cannot find the file specified. 

是映射的網絡驅動器上,我有服務的代碼帳戶設置爲

this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalService; 

這是某種權限問題嗎?是否有任何工具或實用程序來診斷這種問題?

更新:該代碼是一個空的服務

namespace WindowsService1 
{ 
public partial class Service1 : ServiceBase 
{ 
    public Service1() 
    { 
     InitializeComponent(); 

    } 

    protected override void OnStart(string[] args) 
    { 

    } 

    protected override void OnStop() 
    { 
    } 
} 
} 

更新2:該錯誤是當我啓動該服務,而不是當我安裝它。我成功地

M:\MyDocuments\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug>installutil WindowsService1.exe 
+0

這可能是一個權限問題,但沒有代碼很難說。 – Rafa

+0

您需要首先安裝(註冊)服務(請參閱有關sc.exe的幫助,該命令行程序允許您與服務控制器進行交互),然後使用net start和net stop來控制它(或使用'sc start'和'sc stop')。大多數服務也接受一個'/ install'命令行開關,它爲你註冊Windows。 –

回答

0

The code is on a mapped network drive and I have the Service Account set as:

this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalService; 

這聽起來像問題運行以下命令。 LOCALSERVICE帳戶無權查看網絡驅動器。至少該進程需要能夠查看其可執行文件。相當失敗的機制是什麼,我不確定,但肯定這是根本原因。

將文件放到本地驅動器上,然後重試。

+0

謝謝大衛,我有一種感覺,你是正確的。但是,我們的計算機上的本地驅動器被鎖定,服務需要從網絡驅動器啓動。有沒有可以*訪問網絡驅動器或解決此問題的任何服務帳戶?再次感謝 – bischoffingston

+0

您可能需要與您的系統管理員聯繫。但是,您始終可以使用自己的交互式日誌帳戶運行服務。只要管理員沒有拒絕您的帳戶「登錄爲服務」權限。這將是我會嘗試的第一件事。調試時在服務控制面板上配置登錄用戶。無需在此處編寫代碼。 –

相關問題