我在networking中创build了一个简单的Windows服务来运行一个文件。 当我在本地运行服务时,我看到在任务pipe理器中运行的文件就好了。 但是,当我在服务器上运行该服务将不会运行该文件。 我检查了文件的path是好的。 我也检查了文件夹和文件的权限,他们也很好。 也没有例外发生。 以下是用于启动运行该文件的过程的代码。 我首先发布了堆栈溢出 ,有人认为这是一个configuration问题,所以我把它移到这里。 有任何想法吗?
try { // 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(); } catch (Exception ex) { eventLog1.WriteEntry("VirtualCameraService exception - " + ex.InnerException); }
好的,所以问题是文件没有关联到服务器上的程序。 所以,而不是试图打开文件,我需要打开程序运行该文件,然后将该文件作为parameter passing给程序。 以下是语法。
// 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";
尝试用"C:\Path to File.avc" "C:\Path to Program that opens AVC files\ProgramName.exe" "C:\Path to File.AVC" "C:\Path to File.avc"replace"C:\Path to File.avc" "C:\Path to Program that opens AVC files\ProgramName.exe" "C:\Path to File.AVC" ,看看是否改变任何东西。 我曾经见过这种情况发生在某人通过双击文件双击打开某个文件types(交互文件关联)的情况下工作正常,但是当被称为批处理作业,服务或类似文件时,它需要实际的exe名称与作为parameter passing的文件名称。
同时仔细检查一下您的服务是否允许与桌面进行交互(尽pipe取决于您的Windows服务器版本,此选项可能不在此处,因为已在新版本中删除)。