Question

I'm creating a service on VS2010, using .net framework 4.0 Client Profile. The target machine is Windows Server 2003 64 bits. This service move some files and then executes a process with System.Diagnostics.Process. The trouble is that, even if the taskmanager shows a process as starting, the executable never do whats was made for. Example code:

        private void imprimir(string nombreImpresora, int copias, string nombreArchivo)
    {
        try
        {
            string copiasSumatra = "1,";
            for (int i = 1; i < copias; i++)
            {
                copiasSumatra += "1,";
            }

            string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string comando = String.Format("-print-to \"{0}\" \"{1}\" -print-settings \"{2}odd,fit\" -silent", nombreImpresora, nombreArchivo, copiasSumatra);
            string filename = '"' + Path.Combine(path, "SumatraPDF.exe") + '"';
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo.WorkingDirectory = path;
            proc.StartInfo.FileName = filename;
            proc.StartInfo.Arguments = comando;
            proc.StartInfo.RedirectStandardError = false;
            proc.StartInfo.RedirectStandardOutput = false;
            proc.StartInfo.UseShellExecute = true;
            proc.StartInfo.ErrorDialog = false;
            proc.Start();
            proc.WaitForExit();
            lc.writeToLog("Instruction executed. Exit code: " + proc.ExitCode);
        }
        catch (Exception ex)
        {
            lc.writeToLog(ex.Message + " " + ex.StackTrace);
        }
    }

If I execute it on my dev machine (windows 8 pro) or in another test server (Windows Server 2003 32 bits) it makes whats expected. If I run it on the WS2003 64 bit server it does nothing.

I've debugged lots of times to see if it produces some error that I'm missing, but nothing happens. The "lc.writeToLog" method prints text to a file. I've used it to log every single line of the execution, but no error is thrown. Using that method I've concluded that it passes the "proc.WaitForExit()" instruction, so I think it's going to do what I've programmed, but nothing happens.

I have runned the same instruction but passing it a user, password and domain and the result was the same. Also tryed to capture standard error and output but it contained nothing.

What could be the trouble?

Was it helpful?

Solution

It was a server related issue. After deploying the application onto the production server the issue has disapeared.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top