如何在C#中的另一台机器上启动进程? [英] How to start a process in another machine in C#?

查看:59
本文介绍了如何在C#中的另一台机器上启动进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何启动 另一台机器  c#? 



我正在尝试在另一台机器上启动打印过程。我甚至在同一台机器上提供了用户名和密码。我作为服务运行时遇到Access拒绝问题。由于应用程序打印过程有效。

  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 ); // 等待最多10秒才能完成流程
if (!proc.HasExited)
{
proc.Kill();
proc.Dispose();

}

}





我的尝试:



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); //完成整个过程最多等待10秒

if(!proc.HasExited)

{

proc.Kill() ;

proc.Dispose();



}



}

解决方案

你读过 c# - 通过在Windows服务中执行进程进行打印 - 堆栈溢出 [ ^ ]?该服务不得在本地系统帐户下运行,而是在打印机可用的其他帐户上运行。您是否真的更改了服务的登录属性?

您可能需要使用不同的pdf阅读器而不是Adobe,例如福昕。

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.

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

}

}

解决方案

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.


这篇关于如何在C#中的另一台机器上启动进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆