I am trying to print a PDF using ASP (C#) through Adobe Reader -the problem is it does work on my local machine but not on server. On my local it starts Adob eReader in minimized state and I can see the file present inside Printer's "See what's printing" window. But on the server I can see the process has started from Task Manager but there's no UI visible as well no file in printer's list.
I though it may be a permission issue but after trying the following steps - it still does not work.
What I have tried.
As by default it runs under DefaultAppPool user - so I created a new App pool under the admin user, it now starts the process under admin but still I can't see the UI and no output on printer.
I added permission "Allow service to interact with desktop" to IIS Admin Service following this article https://support.microsoft.com/en-us/help/555134 - but no difference.
My current code
string args = string.Format("/s /o /h /t \"{0}\" \"{1}\"", filepath, printerName);
var startInfo = new ProcessStartInfo {
FileName = Properties.Settings.Default.AdobeReaderPath,
Arguments = args,
CreateNoWindow = true,
ErrorDialog = false,
UseShellExecute = false,
Verb = "print",
WindowStyle = ProcessWindowStyle.Minimized,
RedirectStandardInput = true,
RedirectStandardOutput = true
};
var process = Process.Start(startInfo);
In the Application Pool Advanced settings, make sure you set the option
"Load User Profile" to True on the server.
Related
My application creates a set of sub processes that runs in the background. These processes all have logging both to file and to console. Is it posssible to open up cmd and see the console output of a process after it has been created outside of cmd?
var p = new Process
{
StartInfo =
{
FileName = path,
Arguments = arguments,
WindowStyle = ProcessWindowStyle.Hidden
}
};
p.Start();
You can't access the console of the sub-process, but you can redirect the output (stdout and stderr, ideally), and pipe them to your own console/display. An example of redirecting stdout of a sub-process is shown in full on MSDN
after reading all topic about C# runas issues, i still can't find my solution.
My problem here is simple, i'm on a user session with no rights and i want to execute an exe as Admin.
I tried many things like:
var psi = new ProcessStartInfo
{
FileName = "isauq.exe",
UserName = "user",
Domain = "",
Password = pass,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
Process.Start(psi);
With the password as an AppendChild for each characters.
I have the admin credentials but seems like the UAC prompt is still popping up
Is there any solutions in C# or Bat ? Or any solution to automate the user entries in UAC prompt ?
Thanks for your time.
We have our own C++ compiled OCR as .exe file that takes the image location as a parameter and return a string, and we place it in folder within our web-API 2 application folder, now we start the OCR as a process from the web-api, get the output and return it back.
everything works good in a local machine, when we deploy the API in the server, the output cannot be retrieved unless we replace the Application pool identity with the Admin in the application pool. At this stage we need to use the Application pool identity (or any other user but the admin) and still be able to retrieve the output from the process here is our code:
ProcessStartInfo info = new ProcessStartInfo
{
WorkingDirectory = enginepath,
CreateNoWindow = true,
UseShellExecute = false,
FileName = enginepath+"//"+"OCR.exe",
RedirectStandardOutput = true,
Arguments = " "+imageFilepath
};
using (Process process = Process.Start(info))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
return result;
}
}
we tried all the popular ways from giving the right permissions,loading the user profile=true, and still can't be able to retrieve the output.
*we need to be able to get the output within the web server application.
I'm facing a strange problem with the IIS Local. I've developed a webapi Controller that, at some point, opens Excel, makes some processing with macros and then closes. Here's the piece of code that opens Excel with several parameters:
var procStartInfo = new ProcessStartInfo(
this.Parameters[ConsoleExecutionParameters.FileToExecute],
this.ParametersProcessed)
{
CreateNoWindow = false,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
WindowStyle = ProcessWindowStyle.Maximized,
WorkingDirectory = workingDirectory
};
using (var proc = new Process { StartInfo = procStartInfo })
{
try
{
proc.EnableRaisingEvents = true;
proc.Start();
proc.WaitForExit(60000);
proc.StandardInput.Flush();
if (!proc.HasExited)
....
Gotta say that this piece of code WORKS (and opens the excel correctly) if the WebAPI is run under IIS Express. However, when running it under a local IIS, an Excel process is opened (at least it is shown in the task manager) but no Excel window appears, the application seems to hang when "proc.WaitForExit" instruction is called, and EXCEL.EXE process stays like in a "zombie" state. After some time (60 seconds) my application times out and the Excel.EXE process is still hung.
Does someone have any idea about why it works on IIS express and doesn't in Local IIS?
Thanks and kind regards.
I am trying to execute a batch file server-side in IIS to add a printer using the printuientry call.
The problem I am facing is that I am using the Copy To Output Directory - Copy Always and the following code:
var path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
var processInfo = new ProcessStartInfo(Path.Combine(path, "AddPrinter.bat"))
{
CreateNoWindow = true,
UseShellExecute = false,
WorkingDirectory = path,
Arguments = ipAddress,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true
};
var process = Process.Start(processInfo);
process.WaitForExit(10000);
process.Close();
Now when deugging, I have checked the values of path and its set to
file:\C:\_Projects\PrinterServerV2\bin
and I have checked to see if the file and directory exist which they do.
But I get the exception:
System.ComponentModel.Win32Exception (0x80004005): The directory name is invalid
Any ideas please??
Check if the user you had set in the iis configuration does have all privileges to run, access, write and read what you wanna do with your batch file.
Also try to change your ProcessStartInfo like the process will be cmd.exe and your batch file the argument.
I had a similar issue How to execute multiples .BAT files in C#
try AppDomain.CurrentDomain.BaseDirectory as path.