2009-11-09 175 views
0

我在運行文件的dot net中創建了一個簡單的Windows服務。當我在本地運行服務時,我發現在任務管理器中運行的文件很好。但是,當我在服務器上運行服務時,它不會運行該文件。我檢查了文件的路徑,這很好。以下是用於啓動運行該文件的過程的代碼。有任何想法嗎?Windows服務在本地運行文件,但不在服務器上運行

protected override void OnStart(string[] args) 
{ 
    // TODO: Add code here to start your service. 
    eventLog1.WriteEntry("VirtualCameraService started"); 

    // Create An instance of the Process class responsible for starting the newly process. 

    System.Diagnostics.Process process1 = new System.Diagnostics.Process(); 

    // Set the directory where the file resides 
    process1.StartInfo.WorkingDirectory = "C:\\VirtualCameraServiceSetup\\"; 

    // Set the filename name of the file to be opened 
    process1.StartInfo.FileName = "VirtualCameraServiceProject.avc"; 

    // Start the process 
    process1.Start(); 
} 
+0

什麼版本的windows?是否啓用UAC? – djangofan 2009-11-09 16:46:51

+0

它是Windows Server Enterprise 2007.幾乎所有的UAC都被禁用,除了:「僅提升安裝在安全位置的UIAccess應用程序」。 「標準用戶提示提示行爲」設置爲「提示憑據」,並且「管理員批准模式下管理員提升提示行爲」設置爲「不提示提升」 – Ben 2009-11-09 17:59:00

回答

0

我的第一本能是檢查權限。

+0

這是我第一件事情之一也在想。我檢查了所有的權限,他們都是正確的。 – Ben 2009-11-09 16:30:27

0

是否在服務器上註冊了文件擴展名?可能是服務器無法找到與.avc相關的操作。您可能希望將其移至ServerFault,因爲它很可能是配置或Windows操作系統版本的差異。

0

您可能希望在該方法中放置一個try catch塊並寫出事件日誌的任何異常,這應該使您在寫入方向上更進一步。

但正如D.Shawley所說,這聽起來像是一個配置問題。

+0

是的,我認爲這是一個配置問題。我在該方法中放了一個try catch塊,不幸的是沒有拋出異常。 – Ben 2009-11-09 17:23:03

0

好的,問題再次出現在文件沒有關聯到服務器上的程序。因此,不是試圖打開我需要打開程序來運行文件的文件,而是將該文件作爲參數傳遞給程序。以下是語法。

// Set the directory where the file resides 
process1.StartInfo.WorkingDirectory = "C:\\Program Files (x86)\\Axis Communications\\AXIS Virtual Camera 3\\"; 

// Set the filename name of the file to be opened 
//process1.StartInfo.FileName = "VirtualCamera.exe C:\\VirtualCameraServiceSetup\\VirtualCameraServiceProject.avc"; 
process1.StartInfo.FileName = "VirtualCamera.exe"; 
process1.StartInfo.Arguments = "VirtualCameraServiceProject.avc"; 
相關問題