Windows服务在本地运行文件,但不在服务器上运行
问题描述:
我在运行文件的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();
}
答
您可能希望在该方法中放置一个try catch块并写出事件日志的任何异常,这应该使您在写入方向上更进一步。
但正如D.Shawley所说,这听起来像是一个配置问题。
+0
是的,我认为这是一个配置问题。我在该方法中放了一个try catch块,不幸的是没有抛出异常。 – Ben 2009-11-09 17:23:03
答
好的,问题再次出现在文件没有关联到服务器上的程序。因此,不是试图打开我需要打开程序来运行文件的文件,而是将该文件作为参数传递给程序。以下是语法。
// 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";
什么版本的windows?是否启用UAC? – djangofan 2009-11-09 16:46:51
它是Windows Server Enterprise 2007.几乎所有的UAC都被禁用,除了:“仅提升安装在安全位置的UIAccess应用程序”。 “标准用户提示提示行为”设置为“提示凭据”,并且“管理员批准模式下管理员提升提示行为”设置为“不提示提升” – Ben 2009-11-09 17:59:00