Im trying to print a generated pdf on my web app in c# asp.net.
Im using iis.
I need to print the file on a specific printemps over our network. The fact is that in my dev server environnement, in debug, everything works well.
I use process.start(foxitreader exe, the file, and the printer)
But when i release the app, on the prod server ,no more printing. All i got is the process of the terminal and foxit reader showing in task manager, but that’ it.
My question is : is there a way to print my file with This configuration ?
I tried to launch the powershell command directly in terminal, it worked on Both server.
I tried to launch a ..bat file directly that open the powershell script, it worked as well.
But from the app, i still can’t figure how to make it work
Related
I need help with a strange problem that I can't solve. I developed an API as a local server to manage print requests between a web application and the user's PC.
This API is executed by a Windows Service, and it is packaged in an MSI installation package.
So the user installs the Windows service that runs an API on his computer. If the user needs to print something, the web application creates an API request on localhost with the printer parameters and calls the PrintDocument method.
My problem is that when the API calls PrintDocument.Print() after preparing the configuration, nothing happens. Windows print spooler shows that you have a printed document and does not throw an exception or error. And this only happens on the user's PC after installing the service, and it only happens with PDF printers! Physical printers work fine, and debug mode with any printer, including a pdf printer, works fine too.
Any ideas why happens this behaviour?
Thanks!
My code
PrintServer is a class that inherits from System.Drawing.Printing.PrintDocument
It's probably failing from a service because PDF printers need to pop up a file save window and can't do so because it's running under the service context. If you specify a file name, you may be able to avoid this pop up. You can do this by setting the PrintToFile and PrintFileName properties in PrinterSettings:
printer.PrinterSettings.PrintToFile = True
printer.PrinterSettings.PrintFileName = "path-to-pdf.pdf"
I have a windows service that prints InfoPath form's default view using the xdocument.PrintOut() function. It works on several machine configurations except one case. It does not work on some machines running Windows 2012 (and Win2012R2) (x64), SharePoint 2013 (x64), and Office professional plus 2013 (x86). I am not sure if SharePoint has anything to do with the issue.
Here is what's happening when I checked the difference on the process monitor logs.
When executed as a windows service and xdocument.PrintOut() is called, it launches INFOPATH.EXE in background, sends print command, initiates the spoolsv.exe (Printer Spooler), printer spooler detects the default printer and nothing happens afterwards.
When the same code is executed using console app, similer set of events happen and in addition it creates spooler files at "C:\Windows\System32\spool\PRINTERS\FP00003.SPL" and "C:\Windows\System32\spool\PRINTERS\FP00003.SHD". SPL files are the actual spool (print job) files. SHD files provide information about which printer the print job was sent to and from whom the print job came.
Please note that the service runs under the same account as when running the console app and the printer driver is always the same on all systems. Also, running exactly the same code, but by automating MS-Word to print to the same printer from a service, works fine as well.
I tried to explain the problem and please feel free to ask clarification through comments.
Here is the code used in Windows service and console app:
//** Create inforpath application instance
Microsoft.Office.Interop.InfoPath.Application app = new Microsoft.Office.Interop.InfoPath.Application();
//** Open XML file
XDocument xdoc = app.XDocuments.Open(#"F:\InfoPathTestFiles\8f2de6cb86594203b5ecb301cb2f4a94.xml", 1);
//** give enough time for infopath.exe to open the XML file
System.Threading.Thread.Sleep(5000);
//** Send print command.
xdoc.PrintOut();
//** let it cool for 5 seconds.
System.Threading.Thread.Sleep(5000);
//** quit the application.
app.Quit(true);
Please note that the InfoPath file (xml) needs to be fully trusted in order for it to print in this manner.
Have the same issue as here:
Run PowerShell script from ASP.NET
I am trying to run powershell scripts on the server through an asp.net webpage. It works on the local server but does not work remotely. Remotely it returns nothing as if the script worked.
I tried modifying the permissions with icacls.exe
icalc.exe c:\test.ps1 /grant "IIS AppPool\DefaultAppPool:(OI)(CI)F"
This had no effect. When I read what the permissions are:
icalcs c:\test.ps1
NT AUTHORITY\Authenticated Users:(I)(M)
NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Administrators:(I)(F)
BUILTIN\Users:(I)(RX)
I always get the same return even after I try and modify it. Where is IIS AppPool\DefaultAppPool?
Update
I have been using a script that just opens notepad for testing. When I run this locally notepad pops up. Remotely nothing seems to happen, but then I noticed in task manager there were tons of instances of notepad running. So it would seem that it is working but not how I expected. The end function I am trying accomplish is to add minimal remote capabilities. I also play movies off of my webserver and it would be nice to be able to remote some functions through my existing web interface. So the scripts would have to run on the current user. I suppose this may be better suited using WCF or another type of architecture, but it would be nice just to use my web interface for everything.
Make sure that PowerShell script execution has been updated on the remote server to allow script execution. If the web server runs as 32-bit then fire up an x86 PowerShell console on the machine in elevated (admin) mode and execute:
Set-ExecutionPolicy RemoteSigned
If the web page runs as 64-bit then do the same using a 64-bit elevated PowerShell console.
I have a console application that performs some data work and then closes. If I run the executable manually it opens a command prompt, runs the program, and closes. No issues at all regardless of what Microsoft OS I'm using.
However, if I attempt to run the program as a scheduled task it fails on one specific server running Windows Server 2008 R2. It works as a scheduled task just fine on other servers, including another Windows Server 2008 R2 box in the same building. Unfortunately this one server is the server it needs to run on. I've tried adding logging, writing to the event logs, executing the application as an administration, forcing 32 or 64 bit, and launching it as a separate launch from a .bat file. Nothing. The program isn't crashing, it is just never opening.
Does anyone know what may be causing this? I'm at a loss and I don't know what to do.
Edit: I created a test .bat file that just launches a command prompt to see if it would open a command prompt window. It does not. The other tasks seem to run fine though.
Edit #2: I have been researched this and something that has come up is to set the task to enable with desktop. I can't find that option nor can I think of a reason why it would fix this issue but it seems to keep coming up.
After a bit of fiddling around this is what worked for me. When you point to the console application in the actions Tab, ensure that you fill in the 'Start in' field with the location where the executable is located even though it says that it is optional. Once you fill that in, it will work.
I am developing one application which creates PDF. I am using Process.Start(startInfo) to create PDF. Now when I run this application locally, it is working fine and creates PDF but when I deploy it on Development server it is not creating PDF.
I made it very simple to Process.Start("IExplore.exe"), however still it not working on Development server.
Please let me know if any other thing that I have to do it so start working?
You're probably having this issue because on your local machine you're running under your account, which has permissions to run the executable. When deployed to the dev server, it's probably running under the NETWORK SERVICE account, which probably doesn't have permissions to run the executable. You need to look into using impersonation.
I gave a detailed answer on this here:
Invoke or call C# console app from C# web service?