Windows service runs file locally but not on server

servicewindows-service

I created a simple Windows service in dot net which runs a file. When I run the service locally I see the file running in the task manager just fine. However, when I run the service on the server it won't run the file. I've checked the path to the file which is fine. I also checked the permissions on the folder and file, and they fine as well. Also there are no exceptions happening. Below is the code used to launch the process which runs the file. I posted this first on stack overflow, and some people were thinking this is a config issue, so I moved it here. Any ideas?

  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);
        }

Best Answer

Ok, so the problem was that the file wasn't associated to the program on the server. So instead of trying to open the file I needed to open the program to run the file, then pass the file as an argument to the program. Below is the syntax.

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