Printing problem using - System.Diagnostics.ProcessStartInfo startInfo

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi All

Using IIS 6.0 - Windows 2003 Server
ASP.Net 2.0 Framework
C#

Using Impersonation with Network Administrator username/Password


I am attempting to print an Adobe PDF document from a web page

using the code listed at the bottom of this message.

When I press the button to print I get the following output

Both the Adobe Exe and the PDF documents have been copied to the
Namespace on the IIS server.
Tried using @"C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe";
but that does not work either

First am I logged in as the Administrator on the IIS server and
therfore should have the same permissions as the network
adimistrator !!!

Secondly, if not how can I tell who I am logged on as ?

From what I have read I think that the code should work but I cannot
work out why it will not do thge job

Any assistance offered will be greatfully accepted

Best regards

Iain

++++++++++++++++++++++++++++++++++++++++++++
Application Path Is D:\inetpub_dmc_test\wwwroot\TestPrintExample\


File Name = D:\inetpub_dmc_test\wwwroot\TestPrintExample\Web Order
CE41584650 For UPS.pdf
Printer Name = Finance Canon
Acrobat Application Path = D:\inetpub_dmc_test\wwwroot\TestPrintExample
\AcroRd32.exe
Process Created
Applied Arguments : /h /t "D:\inetpub_dmc_test\wwwroot\TestPrintExample
\Web Order CE41584650 For UPS.pdf" "Finance Canon"


Full Exception Details : Error Code = -2147467259
Base Exception Is System.ComponentModel.Win32Exception: Access is
denied at
System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo
startInfo) at System.Diagnostics.Process.Start() at
System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at
TestPrintExample.WebForm1.PrintDoc(String PFileName)
Inner Exception Is


Permission Error : Access is denied



Process Complete
++++++++++++++++++++++++++++++++++++++++++++


The code I am using is

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (! IsPostBack)
{
string pkInstalledPrinters;
for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
{
pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
ddlPrinterList.Items.Add(pkInstalledPrinters);
}
}
}


public void PrintDoc(string PFileName)
{
string AppPath = "";
label1.Text = " ";

string TheAppPath =
HttpContext.Current.Request.PhysicalApplicationPath;
string pdfFileName = TheAppPath + PFileName;

label1.Text = label1.Text + "<br> Application Path Is " +
TheAppPath + "<br> <br>";
label1.Text = label1.Text + "<br>" + "File Name = " +
pdfFileName;

// string printerName = @"\\Dun-Server3\Finance Canon";
string printerName = ddlPrinterList.SelectedItem.Text;
label1.Text = label1.Text + "<br>" + "Printer Name = " +
printerName;

if (TheApp(PFileName) != "UNKNOWN")
{
if (TheApp(PFileName) == "WINWORD")
{
AppPath = @"C:\Program Files\Microsoft Office
\OFFICE11\WINWORD.EXE";
label1.Text = label1.Text + "<br>" + "Word Application Path
= " + AppPath;
}
if (TheApp(PFileName) == "AcroRd32")
{
// AppPath = @"C:\Program Files\Adobe\Acrobat 7.0\Reader
\AcroRd32.exe";
AppPath = TheAppPath + "AcroRd32.exe";
label1.Text = label1.Text + "<br>" + "Acrobat Application
Path = " + AppPath;
}

System.Diagnostics.ProcessStartInfo startInfo = new
ProcessStartInfo();
label1.Text = label1.Text + "<br>" + "Process Created";


// Print PDF file using Acrobat Reader 6.0.
// "/h" - hidden mode
// "/t" - print command following by the file name and printer
name
// "/h /t \"" + pdfFileName + "\" \"" + printerName + "\"";
startInfo.Arguments = "/h /t \"" + pdfFileName + "\" \"" +
printerName + "\"";
label1.Text = label1.Text + "<br>" + "Applied Arguments : " +
startInfo.Arguments;

startInfo.CreateNoWindow = false;
startInfo.WindowStyle = ProcessWindowStyle.Normal; // CHange
To Hidden

startInfo.FileName = AppPath;
startInfo.UseShellExecute = true;
startInfo.Verb = "Print";

if(impersonateValidUser("Administrator", "MyDomain",
"AdminPassword"))
{
try
{
System.Diagnostics.Process process =
Process.Start(startInfo);
process.WaitForExit(30000);
if (process.HasExited == false)
{
label1.Text = label1.Text + "<br><br><br>" + "Process
Has Not Exited : Kill Process" + "<br><br><br>";
process.Kill();
}
}
catch (Win32Exception ex)
{
label1.Text = label1.Text + "<br><br><br>" + "Full
Exception Details : Error Code = " +
ex.ErrorCode + "<br>" + "Base Exception Is
" +
ex.GetBaseException() + "<br>" + "Inner
Exception Is " +
ex.InnerException;
if(ex.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
label1.Text = label1.Text + "<br><br><br>" + "Path
Error : " + ex.Message + "<br><br><br>";
}
else
if (ex.NativeErrorCode == ERROR_ACCESS_DENIED)
{
// Note that if your word processor might generate
exceptions
// such as this, which are handled first.
label1.Text = label1.Text + "<br><br><br>" +
"Permission Error : " + ex.Message + "<br><br><br>";
}
else
{
label1.Text = label1.Text + "<br><br><br>" +
"Permission Error : " + ex.Message + "<br><br><br>";
}
}
}
label1.Text = label1.Text + "<br>" + "Process Complete";
}
}



private void button2_Click(object sender, System.EventArgs e)
{
string LFileName = @"Web Order CE41584650 For UPS.pdf";
PrintDoc(LFileName);
}
.



Relevant Pages

  • Re: [Full-disclosure] Question Regarding IIS 6.0 / Is this a DoS???
    ... As you see in the exception ... Question Regarding IIS 6.0 / Is this a DoS??? ... k> I request this file several times at once. ... k> Stop the attack I get an exception that the Server is too busy/Unhandled ...
    (Full-Disclosure)
  • Re: Web service doesnt run
    ... "Ioannis Vranos" wrote in message ... >> your IIS. ... > Server Error in '/Converter' Application. ... An unhandled exception occurred during the execution of the ...
    (microsoft.public.dotnet.distributed_apps)
  • RE: [Full-disclosure] Question Regarding IIS 6.0 / Is this a DoS???
    ... As you see in the exception ... Question Regarding IIS 6.0 / Is this a DoS??? ... k> I request this file several times at once. ... k> Stop the attack I get an exception that the Server is too busy/Unhandled ...
    (Bugtraq)
  • Re: Web service doesnt run
    ... Also the services ASP .NET State Service, IIS Admin, Server, Web Client, ... Server Error in '/Converter' Application. ... An unhandled exception occurred during the execution of the ... not exist or is not accessible because of security settings. ...
    (microsoft.public.dotnet.distributed_apps)
  • [NT] Heap Overrun in HTR Chunked Encoding Could Enable Web Server Compromise
    ... This patch eliminates a newly discovered vulnerability affecting Internet ... in IIS 4.0 and 5.0, and could likewise be used to overrun heap memory on ... allowing code to be run on the server. ... * Microsoft has long recommended disabling HTR functionality unless there ...
    (Securiteam)