【问题标题】:Windows service runs file locally but not on serverWindows 服务在本地运行文件,但不在服务器上
【发布时间】:2009-11-09 16:21:09
【问题描述】:

我在 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();
}

【问题讨论】:

  • 什么版本的windows?是否启用了 UAC?
  • 它是 Windows Server Enterprise 2007。除了“仅提升安装在安全位置的 UIAccess 应用程序”之外,几乎所有内容都禁用了 UAC。 “标准用户提升提示的行为”设置为“凭据提示”并且“管理员批准模式下管理员的提升提示行为”设置为“不提示提升”

标签: windows-services service


【解决方案1】:

我的第一反应是检查权限。

【讨论】:

  • 是的,这也是我首先想到的事情之一。我检查了所有的权限,它们都是正确的。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    您可能希望在该方法中放置一个 try catch 块并将任何异常写到事件日志中,这应该会引导您进入写入方向。

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

    【讨论】:

    • 是的,我认为这是一个配置问题。我在方法中放了一个try catch块,不幸的是没有抛出异常。
    【解决方案4】:

    好的,问题再次是该文件未与服务器上的程序关联。因此,我不需要尝试打开文件,而是需要打开程序来运行文件,然后将文件作为参数传递给程序。下面是语法。

    // 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";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-07
      • 1970-01-01
      • 2016-04-29
      • 2018-08-16
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多