简体   繁体   中英

.NET webservice attemp to print on a network printer not working

I am working on ac# web service using .net framwork 4.0 and I have a file (print.exe) which executes printing, the file works when I double click it manually, it prints, but when using the webservice it give an error that No printer installed.

this the code of the webmethod:

[WebMethod]
        public String Print_In_Kitchen(Int32 OrderID, String Lang)
        {
            System.Security.SecureString secPass = new System.Security.SecureString();
            string paswd = "96321";
            for (int i = 0; i < paswd.Length; i++)
            {
                secPass.AppendChar(paswd[i]);
            }

            Process proc = new Process();
            proc.StartInfo.FileName = @"C:\EXE_Print.exe";
            proc.StartInfo.Arguments = @"" + OrderID + " " + Lang + " " + "\"" + ConfigurationManager.ConnectionStrings["constr"].ConnectionString + "\"";
            proc.StartInfo.UserName = "omar";
            proc.StartInfo.Password = secPass;
            proc.StartInfo.Domain = "Futec";
            proc.StartInfo.Verb = "runas";

            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.Verb = "runas";
            proc.StartInfo.RedirectStandardInput = true;
            proc.Start();
            string s = proc.StandardOutput.ReadToEnd();
            proc.WaitForExit();

            return s;
}

I have searched for a solution but haven't found any useful link or explanation for this, saw this question here but with no answer: pdf print through .net process and I am new to .NET

My gut feeling is that the User that the Service is running as, doesn't have access to that printer.

You could try changing StartInfo.UseShellExecute to true but I would also check the permissions of your services user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM