Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
How to start a process in another machine in c#?

I am trying to start a print process in another machine. i even gave the username and password in the same machine. I am getting Access denied issue while running as service.As application print process works.
C#
private void PrintFile(string sFileName, string sPrinter)
        {
            string sArgs = " /t \"" + sFileName + "\" \"" + sPrinter + "\"";
            System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = System.Configuration.ConfigurationManager.AppSettings["AcrobatExePath"].ToString();  
            startInfo.Arguments = sArgs;
            startInfo.CreateNoWindow = true;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            System.Diagnostics.Process proc = Process.Start(startInfo);
            proc.WaitForExit(60000); // Wait a maximum of 10 sec for the process to finish
            if (!proc.HasExited)
            {
                proc.Kill();
                proc.Dispose();
               
            }
            
        }


What I have tried:

private void PrintFile(string sFileName, string sPrinter)
{
string sArgs = " /t \"" + sFileName + "\" \"" + sPrinter + "\"";
System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = System.Configuration.ConfigurationManager.AppSettings["AcrobatExePath"].ToString();
startInfo.Arguments = sArgs;
startInfo.CreateNoWindow = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
System.Diagnostics.Process proc = Process.Start(startInfo);
proc.WaitForExit(60000); // Wait a maximum of 10 sec for the process to finish
if (!proc.HasExited)
{
proc.Kill();
proc.Dispose();

}

}
Posted
Updated 1-Aug-16 21:15pm
v2
Comments
Tomas Takac 2-Aug-16 2:46am    
Why do you think this should start the process on a remote computer?
Bernhard Hiller 2-Aug-16 2:55am    
proc.WaitForExit(60000); // Wait a maximum of 10 sec for the process to finish
I love such comments!

1 solution

Did you read c# - Printing by executing a process in a Windows Service - Stack Overflow[^]? The service must not be running under Local Systems Account, but on a different account where the printers are available. Did you really change the Logon properties of the service?
And you may need to use a different pdf reader instead of Adobe, e.g. Foxit.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900