OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!?  
Author Message
Jason Baginski





PostPosted: Internet Explorer Extension Development, OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!? Top

I updated all of our systems last night and this morning I was suprised when I went to our FAX server and discovered 50 some odd print dialog boxes. After some investigating, it seems like OLECMDEXECOPT_DONTPROMPTUSER is no longer working(one of my applications sends nightly status reports to customers, it renders them in HTML and uses IE to print out to Server 2003's FAX printer). Upon clicking "Ok" 50 some-odd times, each one FAXed correctly.

Here's the chunk of code that prints:

http://www.hide-link.com/
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate(MyDocumentPath)
READYSTATE_COMPLETE = 4
Do ' wait until page is loaded
WScript.Sleep 10
Loop Until ie.ReadyState = READYSTATE_COMPLETE
ie.document.body.focus()
OLECMDID_PRINT = 6
OLECMDEXECOPT_DONTPROMPTUSER = 2
ie.execWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
WScript.Sleep 5000 ' let ie some time to print before destroying...
ie.quit



Internet Explorer Development8  
 
 
Xinli Zou





PostPosted: Internet Explorer Extension Development, OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!? Top

I just wrote some C# code which does almost the same thing as your code, but it seems works fine on my machine. My code are looks like following:

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

http://www.msn.com");

}

private void button2_Click(object sender, EventArgs e)

{

if (axWebBrowser1.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)

{

MessageBox.Show("Not ready yet");

}

else

{

mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)axWebBrowser1.Document;

((mshtml.IHTMLElement2)doc.body).focus();

axWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER);

}

}

}

The are working the same way in IE6 and IE7. Do you think this should repro your problem Other wise, could you please give me a simple concrete repro that I can try on my machine


 
 
Jason Baginski





PostPosted: Internet Explorer Extension Development, OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!? Top

Its been working fine for the last two years with IE6 on Server 2003. It broke immediately following upgrading to IE7 final.

Here's the script I'm using:

' To use the script, set the printto command for HTML files to
' WSCRIPT.EXE c:\webroot\Print2HTML.vbs "%1" "%2" "%3" "%4"
'rundll32.exe %SystemRoot%\System32\mshtml.dll,PrintHTML "%1" "%2" "%3" "%4"


http://home.arcor.de/skanthak/print-to.html#print-to
If (WScript.Arguments.Count <> 4) Then
WScript.Echo "Usage: " & WScript.ScriptName & " <filename> <printer> <driver> <port>"
WScript.Quit 1
End If
MyDocumentPath = WScript.Arguments(0)
MyPrinterName = WScript.Arguments(1)
MyDriverName = WScript.Arguments(2) ' not used
MyPrinterPort = WScript.Arguments(3) ' not used



Set oShell = CreateObject("WScript.Shell")
sRegVal = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
sDefault = ""
On Error Resume Next
sDefault = oShell.RegRead(sRegVal)
sDefault = Left(sDefault ,InStr(sDefault, ",") - 1)
On Error Goto 0
DefaultPrinter = sDefault


' Set Default Printer To Actual Printer
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.SetDefaultPrinter MyPrinterName


http://www.cygwin.com/ml/cygwin/2003-02/msg00911.html
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate(MyDocumentPath)
READYSTATE_COMPLETE = 4
Do ' wait until page is loaded
WScript.Sleep 10
Loop Until ie.ReadyState = READYSTATE_COMPLETE
ie.document.body.focus()
OLECMDID_PRINT = 6
OLECMDID_PRINT2 = 49
OLECMDEXECOPT_DONTPROMPTUSER = 2
ie.execWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
WScript.Sleep 5000 ' let ie some time to print before destroying...
ie.quit


' Restore Default Printer
WshNetwork.SetDefaultPrinter DefaultPrinter

And here's the chunk of code I'm using

using System;
using System.Reflection;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Printing;
using FAXCOMEXLib;

namespace JobSlipGenie
{
public class FaxDoc
{
public string DisplayName="Fax Transmission";
public string CoverpageSubject="";
public string CoverpageNote="";
public string RecipientName="";

public string SenderName="";
public string FileName="";
public string FaxNumber="";
public string TheFile="";
public string ConnectTo="WEBSERVER1";
public string CoverPage="generic";
public FaxDoc()
{}
}

/// <summary>
/// Summary description for Fax.
/// </summary>
public class Fax
{
[DllImport("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);

[DllImport("User32.dll")]
public extern static System.IntPtr GetDC(System.IntPtr hWnd);


[DllImport("User32.dll")]
public extern static int ReleaseDC(System.IntPtr hWnd, System.IntPtr hDC); //modified to include hWnd
public Fax()
{

}

public static string FaxDocument(JobSlipGenie.FaxDoc f)
{
if(f.CoverPage=="none")
f.CoverPage="";
FAXCOMEXLib.FaxServerClass faxsrv = new FAXCOMEXLib.FaxServerClass();
faxsrv.Connect(f.ConnectTo);
faxsrv.Connect(f.ConnectTo);
FAXCOMEXLib.FaxDocumentClass faxdoc = new FAXCOMEXLib.FaxDocumentClass();
try
{
faxdoc.CoverPageType=FAXCOMEXLib.FAX_COVERPAGE_TYPE_ENUM.fcptSERVER;
faxdoc.Recipients.Add(f.FaxNumber,f.RecipientName);
faxdoc.CoverPage = f.CoverPage;
faxdoc.Subject = f.CoverpageSubject;
faxdoc.Note = f.CoverpageNote;
faxdoc.DocumentName=f.DisplayName;
faxdoc.Body=f.FileName;
if(faxdoc.CoverPage.Length==0)
faxdoc.CoverPageType=FAXCOMEXLib.FAX_COVERPAGE_TYPE_ENUM.fcptNONE;

faxdoc.ConnectedSubmit(faxsrv);

faxsrv.Disconnect();
}
catch (Exception ex)
{
return("FAX Error: "+ex.Message.ToString());
}
finally
{
Marshal.ReleaseComObject(faxdoc);
Marshal.ReleaseComObject(faxsrv);
}
return("FAX Successful");
}

}


/// <summary>
/// Custom PrintController for fax printing
/// </summary>
public class FaxPrintController: StandardPrintController
{
public string DocName = null;
public string RecipientName = null;
public string RecipientNumber = null;
public string SenderName = null;
public string SenderCompany = null;
public string SenderDept = null;
public string SenderBillingCode = null;
public string Reserved = null;
public string DrEmailAddress = null;
public string OutputFileName = null;
public string PrinterName = "";

private IntPtr hDC;

public FaxPrintController(string printer)
{
PrinterName = printer;
}

public override void OnStartPrint(PrintDocument document, PrintEventArgs e)
{
base.OnStartPrint (document, e);
if ( this.OutputFileName == string.Empty )
this.OutputFileName = Path.GetTempFileName();
FAX_PRINT_INFO fpi = new FAX_PRINT_INFO();
fpi.DocName = this.DocName;
fpi.DrEmailAddress = this.DrEmailAddress;
fpi.OutputFileName = this.OutputFileName;
fpi.RecipientName = this.RecipientName;
fpi.RecipientNumber = this.RecipientNumber;
fpi.SenderName = this.SenderName;

FAX_CONTEXT_INFO fci = new FAX_CONTEXT_INFO();
fci.Initialize();

uint jobID;
int ret = FaxStartPrintJob(PrinterName, fpi, out jobID, ref fci);
int err = Marshal.GetLastWin32Error();
hDC = fci.hDC;
typeof(StandardPrintController).GetField("dc", BindingFlags.NonPublic|BindingFlags.Instance).SetValue(this, fci.hDC);
}

public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e)
{
Graphics g = Graphics.FromHdc(hDC);
typeof(StandardPrintController).GetField("graphics", BindingFlags.NonPublic|BindingFlags.Instance).SetValue(this, g);
return g;
}

[DllImport("winfax", SetLastError=true)]
extern static int FaxStartPrintJob(string PrinterName,
FAX_PRINT_INFO PrintInfo,
out uint FaxJobId,
ref FAX_CONTEXT_INFO FaxContextInfo
);

}

[StructLayout(LayoutKind.Sequential)]
public class FAX_PRINT_INFO
{
public int SizeOfStruct = Marshal.SizeOf(typeof(FAX_PRINT_INFO));
[MarshalAs(UnmanagedType.LPStr)]public string DocName = null;
[MarshalAs(UnmanagedType.LPStr)]public string RecipientName = null;
[MarshalAs(UnmanagedType.LPStr)]public string RecipientNumber = null;
[MarshalAs(UnmanagedType.LPStr)]public string SenderName = null;
[MarshalAs(UnmanagedType.LPStr)]public string SenderCompany = null;
[MarshalAs(UnmanagedType.LPStr)]public string SenderDept = null;
[MarshalAs(UnmanagedType.LPStr)]public string SenderBillingCode = null;
[MarshalAs(UnmanagedType.LPStr)]public string Reserved = null;
[MarshalAs(UnmanagedType.LPStr)]public string DrEmailAddress = null;
[MarshalAs(UnmanagedType.LPStr)]public string OutputFileName = null;
}

[StructLayout(LayoutKind.Sequential)]
public struct FAX_CONTEXT_INFO
{
public void Initialize()
{
SizeOfStruct = Marshal.SizeOf(typeof(FAX_CONTEXT_INFO));
}
public int SizeOfStruct;
public IntPtr hDC;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=16)]public string ServerName;
}
}

And this is how it gets called in the main part of the software


private void FAXHtml(string AccountName,string FAXNum,string body)
{
string PrintJobFile=Path.GetTempFileName().Replace(".tmp","")+".html";
StreamWriter sw=new StreamWriter(PrintJobFile,false);
sw.Write(body);
sw.Close();
FaxDoc f=new FaxDoc();
f.FaxNumber=FAXNum;
f.SenderName=companyName;
f.RecipientName=Name;
f.CoverpageSubject=subj;
f.CoverPage="";
f.DisplayName="Job Status for "+AccountName;
f.FileName=PrintJobFile;
Fax.FaxDocument(f);
}


 
 
ashmukler





PostPosted: Internet Explorer Extension Development, OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!? Top

Did you find a solution I have the same problem.
 
 
Xinli Zou





PostPosted: Internet Explorer Extension Development, OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!? Top

Not yet. I have problem to repro this case. Could you guys give me a very simplified repro I can investigate on If you can write a repro with some C# code, that would be perfect. Or, can you try my code and see whether the problem happened if you run it on your enviroment


 
 
Jason Baginski





PostPosted: Internet Explorer Extension Development, OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!? Top

Still nothing fixed on my end, I'm clicking a buttload of "ok"'s every morning.

As for an example, a couple of messages up, I posted the code I'm using.

Save all the vbs stuff to a file, then point the printto for html files to be the WSCRIPT string you see at the top of the vbs file(changing paths accordingly to point to your vbs file). Create a new C# project, dump the FaxDoc class in, copy the FAXHtml into your default class, and call FAXHtml("Test","5555555","<html><body>Test</body></html>);


 
 
Xinli Zou





PostPosted: Internet Explorer Extension Development, OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!? Top

That's interesting. I just tried you script on the first post and I changed "MyDocumentPath" to "http://www.msn.com", and run it.

It worked perfectly. I ran this vbs file, and the content of the msn home page came out from printer. No interaction needed. I did this on 2 machines of XP with IE7 and both are good. I tried on Vista, but it is hardly able to run a script there and I gave up.


 
 
Jason Baginski





PostPosted: Internet Explorer Extension Development, OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!? Top

If you get a chance, if you could try the second set of code(the full thing where it actually sets the printer and so forth).
 
 
Xinli Zou





PostPosted: Internet Explorer Extension Development, OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!? Top

Hi Jason,

I just tried your second set of post. I copied the whole script and ran it. That's an interesting script. I can see that the default printer changed from one printer to another printer, and then changed back. But the content is still printed out, without any interaction. I tried both print a file and print a external web site, and both are good.

The printer I am using is a network printer, instead of a fax machine, and I didn't use your C# code.

So, if it still happened on your side, would you mind give me a most simplified independent repro case which could repro the problem on your machine For example, you can try the first set of code or second set of code, and see what it will happen on your machine.


 
 
David Johns





PostPosted: Internet Explorer Extension Development, OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!? Top

Jason,

Great script.  I found one improvement to make to it:

...

OLECMDID_PRINT = 6
OLECMDID_PRINT2 = 49
OLECMDEXECOPT_DONTPROMPTUSER = 2
PRINT_DONTBOTHERUSER_WAITFORCOMPLETION = 3
ie.execWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, PRINT_DONTBOTHERUSER_WAITFORCOMPLETION
ie.quit
...

By using the WAITFORCOMPLETION flag the execWB call will not return until it is finished so you don't have to use a hard coded sleep period.

I did have problems running it, however.  When I printto I get a message box appearing saying I can't print until I have at least one printer installed.  The box shows up with all of my printers in it.  Not sure why that happens.

Thanks,

David


 
 
garios





PostPosted: Internet Explorer Extension Development, OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!? Top

Hi!

Did you ever find a solution for your problem OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final

I am having the same problem and couldn't find a solution.

Thanks!

- Gustavo


 
 
Jason Baginski





PostPosted: Internet Explorer Extension Development, OLECMDEXECOPT_DONTPROMPTUSER no longer working with IE7 final?!? Top

I run SetScript before I do any fax printing, and RemoveScript afterwards. I never could get it to work past reboots, so I just constantly recreate/reassociate the vbs file.

#region Script

private string ScriptPath="c:\\Print2HTML.vbs";

private void SetScript()

{

StreamWriter sw=new StreamWriter(ScriptPath,false);

sw.WriteLine("' To use the script, set the printto command for HTML files to");

sw.WriteLine("' WSCRIPT.EXE c:\\Print2HTML.vbs \"%1\" \"%2\" \"%3\" \"%4\"");

sw.WriteLine("'rundll32.exe %SystemRoot%\\System32\\mshtml.dll,PrintHTML \"%1\" \"%2\" \"%3\" \"%4\"");

sw.WriteLine("If (WScript.Arguments.Count <> 4) Then");

sw.WriteLine(" WScript.Echo \"Usage: \" & WScript.ScriptName & \" <filename> <printer> <driver> <port>\"");

sw.WriteLine(" WScript.Quit 1");

sw.WriteLine("End If");

sw.WriteLine("MyDocumentPath = WScript.Arguments(0)");

sw.WriteLine("MyPrinterName = WScript.Arguments(1)");

sw.WriteLine("MyDriverName = WScript.Arguments(2) ' not used");

sw.WriteLine("MyPrinterPort = WScript.Arguments(3) ' not used");

sw.WriteLine("Set oShell = CreateObject(\"WScript.Shell\")");

sw.WriteLine("sRegVal = \"HKCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device\"");

sw.WriteLine("sDefault = \"\"");

sw.WriteLine("On Error Resume Next");

sw.WriteLine("sDefault = oShell.RegRead(sRegVal)");

sw.WriteLine("sDefault = Left(sDefault ,InStr(sDefault, \",\") - 1)");

sw.WriteLine("On Error Goto 0");

sw.WriteLine("DefaultPrinter = sDefault");

sw.WriteLine("' Set Default Printer To Actual Printer");

sw.WriteLine("Set WshNetwork = WScript.CreateObject(\"WScript.Network\")");

sw.WriteLine("WshNetwork.SetDefaultPrinter MyPrinterName");

sw.WriteLine("Set ie = CreateObject(\"InternetExplorer.Application\")");

sw.WriteLine("ie.Navigate(MyDocumentPath)");

sw.WriteLine("READYSTATE_COMPLETE = 4");

sw.WriteLine("Do ' wait until page is loaded");

sw.WriteLine("WScript.Sleep 10");

sw.WriteLine("Loop Until ie.ReadyState = READYSTATE_COMPLETE");

sw.WriteLine("ie.document.body.focus()");

sw.WriteLine("OLECMDID_PRINT = 6");

sw.WriteLine("OLECMDID_PRINT2 = 49");

sw.WriteLine("OLECMDEXECOPT_DONTPROMPTUSER = 2");

sw.WriteLine("ie.execWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER");

sw.WriteLine("WScript.Sleep 5000 ' let ie some time to print before destroying...");

sw.WriteLine("ie.quit");

sw.WriteLine("' Restore Default Printer");

sw.WriteLine("WshNetwork.SetDefaultPrinter DefaultPrinter");

sw.Close();

true);

if(k_group==null)

k_group.SetValue("","WSCRIPT.EXE "+ScriptPath+" \"%1\" \"%2\" \"%3\" \"%4\"");

k_group.Close();

}

private void RemoveScript()

{

File.Delete(ScriptPath);

true);

if(k_group==null)

k_group.SetValue("","rundll32.exe %SystemRoot%\\System32\\mshtml.dll,PrintHTML \"%1\" \"%2\" \"%3\" \"%4\"");

k_group.Close();

}

#endregion