Print without prompting

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
lilsizzo
Posts: 2
Joined: Thu Aug 19, 2010 3:54 pm

Print without prompting

Post by lilsizzo » Thu Aug 19, 2010 3:59 pm

Hi there, is there any possibility to make this vbscript acceptable in hta? It is currently workin in IE but not HTA.<script language='VBScript'> Sub Print() OLECMDID_PRINT = 6 OLECMDEXECOPT_DONTPROMPTUSER = 2 OLECMDEXECOPT_PROMPTUSER = 1 call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1) End Sub document.write "<object ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>" </script>

User avatar
lilsizzo
Posts: 2
Joined: Thu Aug 19, 2010 3:54 pm

Print without prompting

Post by lilsizzo » Thu Aug 19, 2010 3:59 pm

Hi there, is there any possibility to make this vbscript acceptable in hta? It is currently workin in IE but not HTA.<script language='VBScript'> Sub Print() OLECMDID_PRINT = 6 OLECMDEXECOPT_DONTPROMPTUSER = 2 OLECMDEXECOPT_PROMPTUSER = 1 call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1) End Sub document.write "<object ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>" </script>

User avatar
jvierra
Posts: 13482
Joined: Tue May 22, 2007 9:57 am
Contact:

Print without prompting

Post by jvierra » Thu Aug 19, 2010 4:34 pm

Put the following in a file with an hta EXTENSION.

Code: Select all

<input type="button" value="Print Me" onclick='print()'/>
When all good men come to the aid of their party ... and party dood! 
When all good men come to the aid of their party ... and party dood!
jvierra2010-08-19 23:37:31

User avatar
jvierra
Posts: 13482
Joined: Tue May 22, 2007 9:57 am
Contact:

Print without prompting

Post by jvierra » Thu Aug 19, 2010 5:42 pm

YOu cannot do that.

I posted code for you to test. Just put it in an HTA with nothing wlse to see how it works.

YOu are, for some unknown reason, trying to add you old non-functionaly code to the correct code posted.

This goes in a file with an HTA extension

Code: Select all

<input type="button" value="Print Me" onclick='print()'/>
Hello World will print now!

Nothing else. Just those two lines.

User avatar
jvierra
Posts: 13482
Joined: Tue May 22, 2007 9:57 am
Contact:

Print without prompting

Post by jvierra » Thu Aug 19, 2010 10:49 pm

Here is the documentation for the 'print' method of WIndows.

http://msdn.microsoft.com/en-us/library ... S.85).aspx

The object you are trying to use will not work in IE or in an HTA. The object has been disabled for security reasons.

The code I posted is the minimum code needed to demonstrate the function.

Note that ny file, even an empty file will run as an hta if you give it an HTA extension.

Try creating an empty HTA file and running it. Use the "View Source" menu item to look at teh file. You will be surprised by what seems to be in a file that is empty.

This can be usefule if you forget the structure of an HTML file as you can copy and paste this and it will have been created by WIndows. Sort of auto file generation.

COntents of an empty file.

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML><HEAD> 
<META content="text/html; charset=windows-1252" http-equiv=Content-Type></HEAD> 
<BODY></BODY></HTML>

This is because the browser is required by HTML rules to provide default base items for a page.

User avatar
jvierra
Posts: 13482
Joined: Tue May 22, 2007 9:57 am
Contact:

Print without prompting

Post by jvierra » Thu Aug 19, 2010 11:13 pm

THe object will not run in an HTA.

jvierra2010-08-20 06:16:38

User avatar
jvierra
Posts: 13482
Joined: Tue May 22, 2007 9:57 am
Contact:

Print without prompting

Post by jvierra » Mon Aug 23, 2010 2:57 pm

That's right. You can't do hidden printing. It hasn't been available for years even if there are Internet posts to the contrary.
jvierra2010-08-24 03:22:57

Locked