English 中文(简体)
Windows service runs file locally but not on server
原标题:

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. Below is the code used to launch the process which runs the file. Any ideas?

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();
}
问题回答

My first instinct is to check permissions.

Is the file extension registered on the server? It could be that the server is failing to find an action associated with .avc. You might want to move this to ServerFault since it is most likely a configuration or Windows OS version difference.

You may want to put a try catch block in that method and write out any exception to the event log, this should piont you in the write direction.

But as D.Shawley said it sounds like a config issue.

Ok, once again 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";




相关问题
windows service : configuration UI implementation options

I have a simple windows service, that might need to be configured on-the-fly (a COM port to listen to). I have done the UI as a console app that connects to the windows service through WCF, it works ...

Installing a Windows Service as a user

I m currently in the process of creating a Windows service application which will monitor changes to certain keys made in the HKEY_USERS registry. The way I do this is by collecting the SID of the ...

Writing application for both Unix and Windows

I ll write a program for Interactive UNIX (http://en.wikipedia.org/wiki/INTERACTIVE_UNIX). But in a year it will be ported to Windows. I ll write it in ANSI C and/or SH-script. When it runs on Windows ...

Windows service runs file locally but not on server

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 ...

热门标签