Windows服务在本地运行文件但不在服务器上运行

时间:2009-11-09 16:21:10

标签: windows-services service

我在dot net中创建了一个运行文件的简单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();
}

4 个答案:

答案 0 :(得分:0)

我的第一直觉是检查权限。

答案 1 :(得分:0)

文件扩展名是否已在服务器上注册?可能是服务器无法找到与.avc关联的操作。您可能希望将其移至ServerFault,因为它很可能是配置或Windows操作系统版本差异。

答案 2 :(得分:0)

您可能希望在该方法中放置一个try catch块并写出事件日志中的任何异常,这应该会使您处于写入方向。

但正如D.Shawley所说,这听起来像配置问题。

答案 3 :(得分: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";
相关问题