Discussion:
VBScript, print
(too old to reply)
PaulM
2014-04-05 23:55:22 UTC
Permalink
How would get this VBScript to print the msg window?

'Retrieve your windows Product Key

Dim Objshell, sInput, sMsg

Set wshShell=CreateObject("wscript.shell")

If WScript.Arguments.Count = 0 Then
Set Objshell = CreateObject("Shell.Application")
Objshell.ShellExecute "wscript.exe", """" & _
WScript.ScriptFullName & """" &_
" RunAsAdministrator", , "runas", 1
Else

sMsg = "This script will retrieve your Windows Product Key." & vbCr & vbCr
_
& "If you do not trust the source of this information, do not run this
VBScript." & vbCr & vbCr _
& "Would you like to continue?"

sInput = MsgBox(sMsg, vbYesNo + vbInformation, "Paul's XP, Vista Windows 7
and Windows 8 Tweaks")
If sInput = vbYes Then
const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
strValueName = "DigitalProductId"
strComputer = "."

dim iValues()

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,iValues
Dim arrDPID
arrDPID = Array()
For i = 52 to 66
ReDim Preserve arrDPID( UBound(arrDPID) + 1 )
arrDPID( UBound(arrDPID) ) = iValues(i)

Next

Dim arrChars
arrChars =
Array("B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9")
For i = 24 To 0 Step -1
k = 0
For j = 14 To 0 Step -1
k = k * 256 Xor arrDPID(j)
arrDPID(j) = Int(k / 24)
k = k Mod 24

Next

strProductKey = arrChars(k) & strProductKey

If i Mod 5 = 0 And i <> 0 Then strProductKey = "-" & strProductKey

Next

strFinalKey = strProductKey
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
strOS = objOperatingSystem.Caption
strBuild = objOperatingSystem.BuildNumber
strSerial = objOperatingSystem.SerialNumber
strRegistered = objOperatingSystem.RegisteredUser

Next

MsgBox "" & strOS & vbCr & vbcr & _
"Build Number: " & strBuild & vbCr & _
"Registered to: " & strRegistered & vbCr & vbCr & _
"PID: " & strSerial & vbCr & vbCr & _
"Your Windows Product Key is:" & vbCr & strFinalKey & vbCr & vbCr & _
"This script was downloaded from www.paulsxp.com" ,64,"Microsoft Windows
License Information"

If MsgBox("If you find this script was helpful and you would like to make a
Donation?" & vbCr & vbCr & "Click Yes to visit my Donation page at Paul's
Web Site." & vbCr & vbCr & _
"All donations are made thru PayPal®.", vbInformation + vbYesNo +
vbDefaultButton, "Make a Donation") = 6 Then
WshShell.Run "http://www.paulsxp.com/donation.html"
End If
End If
End If
Mayayana
2014-04-06 00:16:44 UTC
Permalink
| How would get this VBScript to print the msg window?
|

You can write it to disk as a text file and print that,
or you can use Ctl + C to copy the message window
and then paste that somewhere to print it.
Dave "Crash" Dummy
2014-04-09 16:56:39 UTC
Permalink
| How would get this VBScript to print the msg window? |
You can write it to disk as a text file and print that, or you can
use Ctl + C to copy the message window and then paste that somewhere
to print it.
How can you print text or a file with a script? Copying to the old
standby's LPT1 and PRN doesn't work, even with a command box. My printer
is connected to a USB port.
--
Crash

Give a man a fish, and he eats for a day.
Teach a man to fish, and his wife hates you for a lifetime.
Dave "Crash" Dummy
2014-04-09 17:17:15 UTC
Permalink
Post by Dave "Crash" Dummy
| How would get this VBScript to print the msg window? |
You can write it to disk as a text file and print that, or you can
use Ctl + C to copy the message window and then paste that
somewhere to print it.
How can you print text or a file with a script? Copying to the old
standby's LPT1 and PRN doesn't work, even with a command box. My
printer is connected to a USB port.
My printer port is identified as USB0, but I still can't get it to print
from the command line. If I use

"d:\>copy file.txt USB0"

I get a return of

"1 file copied"

but nothing happens. The file is not added to the printer queue. I also
tried

"d:\>type file.txt>USB0"

without success.
--
Crash

A line in the sand doesn't mean much if it disappears at high tide.
Mayayana
2014-04-09 22:22:33 UTC
Permalink
I've never tried printing straight from VBS. I don't know
of any object for that. If I had to do it I'd probably try
to automate IE, but I've never had occasion to research it.
Dave "Crash" Dummy
2014-04-09 22:30:43 UTC
Permalink
Post by Mayayana
I've never tried printing straight from VBS. I don't know
of any object for that. If I had to do it I'd probably try
to automate IE, but I've never had occasion to research it.
How would one automate IE to print a document instead of displaying it?
--
Crash

"Patriotism is the last refuge of a scoundrel."
~ Samuel Johnson ~
Mayayana
2014-04-10 00:37:04 UTC
Permalink
| How would one automate IE to print a document instead of displaying it?

It would have to be displayed, or at least loaded
into an IE window. I didn't mention that to the OP
because there are so many problems these days
with security restrictions automating IE. I'm not
sure if it can be done on Vista/7 without running
into a problem.

The code is IE.ExecWB 6, 0

6: print
0: OLECMDEXECOPT_DODEFAULT = 0,
OLECMDEXECOPT_PROMPTUSER = 1,
OLECMDEXECOPT_DONTPROMPTUSER = 2,
OLECMDEXECOPT_SHOWHELP = 3

One would need to load a file or write a string
to a document object. Then call ExecWB. I wouldn't
be surprised if there's a better way to do it, without
needing MS Office or any other special software
installed, but I just don't know.
Todd Vargo
2014-04-10 01:11:09 UTC
Permalink
Post by Dave "Crash" Dummy
Post by Dave "Crash" Dummy
| How would get this VBScript to print the msg window? |
You can write it to disk as a text file and print that, or you can
use Ctl + C to copy the message window and then paste that somewhere
to print it.
How can you print text or a file with a script? Copying to the old
standby's LPT1 and PRN doesn't work, even with a command box. My
printer is connected to a USB port.
My printer port is identified as USB0, but I still can't get it to print
from the command line. If I use
"d:\>copy file.txt USB0"
I get a return of
"1 file copied"
but nothing happens. The file is not added to the printer queue. I also
tried
"d:\>type file.txt>USB0"
without success.
This way still works from the command prompt.

notepad /p file.txt

Simply nestle it into a .Run statement to use in a VBScript in order to
print to whatever is the default printer. Unfortunately, I am unaware of
a way to select a different printer port using this method.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Evertjan.
2014-04-10 08:32:50 UTC
Permalink
Post by Todd Vargo
This way still works from the command prompt.
notepad /p file.txt
Simply nestle it into a .Run statement to use in a VBScript in order to
print to whatever is the default printer. Unfortunately, I am unaware of
a way to select a different printer port using this method.
Use MSDOS "print".

Share your desired printer [W8.1 tested]:

1 open Start > Control Panel > Devices and Printers.
2 right-click the printer you want to use and select Properties.
3 in the Sharing tab, decide to share the printer
3 assign a share name to it. [myHP]

and do:

print /d://myComputerName\myHP F:\myDirectory\myFile.txt

[where myComputerName should be the name you use
and and myHP the actual sharename you invented]

==============================

Perhaps you should read this:

<http://www.robvanderwoude.com/printfiles.php>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dave "Crash" Dummy
2014-04-10 12:52:39 UTC
Permalink
Post by Evertjan.
Post by Todd Vargo
This way still works from the command prompt.
notepad /p file.txt
Simply nestle it into a .Run statement to use in a VBScript in
order to print to whatever is the default printer. Unfortunately, I
am unaware of a way to select a different printer port using this
method.
Use MSDOS "print".
1 open Start > Control Panel > Devices and Printers. 2 right-click
the printer you want to use and select Properties. 3 in the Sharing
tab, decide to share the printer 3 assign a share name to it. [myHP]
print /d://myComputerName\myHP F:\myDirectory\myFile.txt
[where myComputerName should be the name you use and and myHP the
actual sharename you invented]
==============================
<http://www.robvanderwoude.com/printfiles.php>
DOH!! My senior memory fails me again. I already have that Notepad
gimmick in my notes. I just never used it for anything:

'--------------- docprint.vbs -------------------------------------
Set WshShell = CreateObject("Wscript.Shell")
sTextFileName="e:\buffer\binary.txt"
WshShell.run "notepad /p " & sTextFileName, 0, True
--
Crash

Dogs have masters. Cats have attendants.
Evertjan.
2014-04-10 15:23:28 UTC
Permalink
Post by Dave "Crash" Dummy
Post by Evertjan.
Post by Todd Vargo
This way still works from the command prompt.
notepad /p file.txt
Simply nestle it into a .Run statement to use in a VBScript in
order to print to whatever is the default printer. Unfortunately, I
am unaware of a way to select a different printer port using this
method.
Use MSDOS "print".
1 open Start > Control Panel > Devices and Printers. 2 right-click
the printer you want to use and select Properties. 3 in the Sharing
tab, decide to share the printer 3 assign a share name to it. [myHP]
print /d://myComputerName\myHP F:\myDirectory\myFile.txt
[where myComputerName should be the name you use and and myHP the
actual sharename you invented]
==============================
<http://www.robvanderwoude.com/printfiles.php>
DOH!! My senior memory fails me again. I already have that Notepad
'--------------- docprint.vbs -------------------------------------
Set WshShell = CreateObject("Wscript.Shell")
sTextFileName="e:\buffer\binary.txt"
WshShell.run "notepad /p " & sTextFileName, 0, True
Well yes,
but that does not let you choose a printer in the VBS-string
as requested by Tod.

Using shared printer names does.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dave "Crash" Dummy
2014-04-10 18:27:09 UTC
Permalink
Post by Evertjan.
Post by Dave "Crash" Dummy
Post by Evertjan.
Post by Todd Vargo
This way still works from the command prompt.
notepad /p file.txt
Simply nestle it into a .Run statement to use in a VBScript in
order to print to whatever is the default printer. Unfortunately, I
am unaware of a way to select a different printer port using this
method.
Use MSDOS "print".
1 open Start > Control Panel > Devices and Printers. 2 right-click
the printer you want to use and select Properties. 3 in the Sharing
tab, decide to share the printer 3 assign a share name to it. [myHP]
print /d://myComputerName\myHP F:\myDirectory\myFile.txt
[where myComputerName should be the name you use and and myHP the
actual sharename you invented]
==============================
<http://www.robvanderwoude.com/printfiles.php>
DOH!! My senior memory fails me again. I already have that Notepad
'--------------- docprint.vbs -------------------------------------
Set WshShell = CreateObject("Wscript.Shell")
sTextFileName="e:\buffer\binary.txt"
WshShell.run "notepad /p " & sTextFileName, 0, True
Well yes,
but that does not let you choose a printer in the VBS-string
as requested by Tod.
No, I was asking for my own information.
Post by Evertjan.
Using shared printer names does.
Anyway, I can't get the shared printer method to work in my Windows 7
system.
--
Crash

"When you get to a fork in the road, take it."
~ Yogi Berra ~
Evertjan.
2014-04-10 19:05:49 UTC
Permalink
[...]
Post by Dave "Crash" Dummy
Post by Evertjan.
Post by Evertjan.
Use MSDOS "print".
1 open Start > Control Panel > Devices and Printers. 2 right-click
the printer you want to use and select Properties. 3 in the Sharing
tab, decide to share the printer 4 assign a share name to it. [myHP]
print /d://myComputerName\myHP F:\myDirectory\myFile.txt
[where myComputerName should be the name you use and and myHP the
actual sharename you invented]
[..]
Post by Dave "Crash" Dummy
Post by Evertjan.
Using shared printer names does.
Anyway, I can't get the shared printer method to work in my Windows 7
system.
That is strange, I used a W7 advice and implemented it on W8.1

Can anyone else test this?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
GS
2014-04-10 21:37:35 UTC
Permalink
Works exactly as expected on my Win7 Pro machine!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2014-04-10 21:41:39 UTC
Permalink
Post by GS
Works exactly as expected on my Win7 Pro machine!
Though it did print the same doc twice! What's up with that?
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2014-04-10 21:48:57 UTC
Permalink
Post by GS
Post by GS
Works exactly as expected on my Win7 Pro machine!
Though it did print the same doc twice! What's up with that?
Might have been a hicup! I can't double-click (I have Lou Gehrig's) and
so I may have sent it twice the first time. Subsequent sends just
printed once!<g>
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Evertjan.
2014-04-10 22:56:45 UTC
Permalink
Post by GS
Post by GS
Works exactly as expected on my Win7 Pro machine!
Though it did print the same doc twice! What's up with that?
Even better than expected ;-)
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
GS
2014-04-10 22:12:18 UTC
Permalink
I just noticed I didn't specify the printer and so it printed with the
default. But then, I was using the notepad method since the following
doesn't work...

1 open Start > Control Panel > Devices and Printers. 2 right-click the
printer you want to use and select Properties. 3 in the Sharing tab,
decide to share the printer 3 assign a share name to it. [myHP]

and do:

print /d://myComputerName\myHP F:\myDirectory\myFile.txt

[where myComputerName should be the name you use and and myHP the
actual sharename you invented]

..because it generates a syntax error, not like the 7th character.
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Dave "Crash" Dummy
2014-04-11 00:53:05 UTC
Permalink
Post by GS
I just noticed I didn't specify the printer and so it printed with the
default. But then, I was using the notepad method since the following
doesn't work...
1 open Start > Control Panel > Devices and Printers.
2 right-click the printer you want to use and select Properties.
3 in the Sharing tab, decide to share the printer 3 assign a share name to it. [myHP]
print /d://myComputerName\myHP F:\myDirectory\myFile.txt
[where myComputerName should be the name you use and and myHP the actual
sharename you invented]
..because it generates a syntax error, not like the 7th character.
That is what happens to me. First of all, the forward slashes aren't right

E:\Buffer>print /d://HAL9000\canon e:\buffer\fontlist.txt
Invalid switch - //HAL9000\canon

If I replace the forward slashes with back slashes, it appears to work

E:\Buffer>print /d:\\HAL9000\canon e:\buffer\fontlist.txt
E:\buffer\fontlist.txt is currently being printed

But nothing gets printed.
--
Crash

"Something there is that doesn't love a wall, that wants it down."
~ Robert Frost ~
GS
2014-04-11 02:28:33 UTC
Permalink
Post by Dave "Crash" Dummy
Post by GS
I just noticed I didn't specify the printer and so it printed with
the default. But then, I was using the notepad method since the
following doesn't work...
1 open Start > Control Panel > Devices and Printers. 2 right-click
the printer you want to use and select Properties. 3 in the Sharing
tab, decide to share the printer 3 assign a share name to it.
[myHP]
print /d://myComputerName\myHP F:\myDirectory\myFile.txt
[where myComputerName should be the name you use and and myHP the
actual sharename you invented]
..because it generates a syntax error, not like the 7th character.
That is what happens to me. First of all, the forward slashes aren't right
E:\Buffer>print /d://HAL9000\canon e:\buffer\fontlist.txt
Invalid switch - //HAL9000\canon
If I replace the forward slashes with back slashes, it appears to work
E:\Buffer>print /d:\\HAL9000\canon e:\buffer\fontlist.txt
E:\buffer\fontlist.txt is currently being printed
But nothing gets printed.
I looked this up in Script56.chm looking for correct syntax and found
nothing that resembles any of this. What's with the...

E:\Buffer>print

..part? It appears to be something one would see in a CMD window!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Evertjan.
2014-04-11 07:04:38 UTC
Permalink
Post by GS
Post by Dave "Crash" Dummy
Post by GS
I just noticed I didn't specify the printer and so it printed with
the default. But then, I was using the notepad method since the
following doesn't work...
1 open Start > Control Panel > Devices and Printers. 2 right-click
the printer you want to use and select Properties. 3 in the Sharing
tab, decide to share the printer 3 assign a share name to it. [myHP]
print /d://myComputerName\myHP F:\myDirectory\myFile.txt
[where myComputerName should be the name you use and and myHP the
actual sharename you invented]
..because it generates a syntax error, not like the 7th character.
That is what happens to me. First of all, the forward slashes aren't right
E:\Buffer>print /d://HAL9000\canon e:\buffer\fontlist.txt
Invalid switch - //HAL9000\canon
If I replace the forward slashes with back slashes, it appears to work
E:\Buffer>print /d:\\HAL9000\canon e:\buffer\fontlist.txt
E:\buffer\fontlist.txt is currently being printed
But nothing gets printed.
I looked this up in Script56.chm looking for correct syntax and found
nothing that resembles any of this. What's with the...
E:\Buffer>print
..part? It appears to be something one would see in a CMD window!
Perhaps you assigned a share name, but did not activate the same?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
GS
2014-04-11 20:34:15 UTC
Permalink
Post by Evertjan.
Perhaps you assigned a share name, but did not activate the same?
I folowed your instructions explicitly!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2014-04-11 20:38:43 UTC
Permalink
Post by GS
Post by Evertjan.
Perhaps you assigned a share name, but did not activate the same?
I folowed your instructions explicitly!
I didn't use a CMD window, though, thinking what you posted was
VBScript!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Evertjan.
2014-04-12 09:33:41 UTC
Permalink
Post by GS
Post by GS
Post by Evertjan.
Perhaps you assigned a share name, but did not activate the same?
I folowed your instructions explicitly!
I didn't use a CMD window, though, thinking what you posted was
VBScript!
Better first try cmd of powershell.

If that works, use vbs.

Something like
<http://ss64.com/vb/run.html>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
GS
2014-04-12 19:29:51 UTC
Permalink
Post by Evertjan.
Post by GS
Post by GS
Post by Evertjan.
Perhaps you assigned a share name, but did not activate the same?
I folowed your instructions explicitly!
I didn't use a CMD window, though, thinking what you posted was
VBScript!
Better first try cmd of powershell.
If that works, use vbs.
Something like
<http://ss64.com/vb/run.html>
Thanks!
I doubt I'd ever print this way, though! I was more curious as to the
how of it than anything else. The notepad approach is more likely how
I'd go if need be, though, since most my stuff is either VB[A] or C++!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Dave "Crash" Dummy
2014-04-11 16:03:55 UTC
Permalink
Post by GS
I looked this up in Script56.chm looking for correct syntax and found
nothing that resembles any of this. What's with the...
E:\Buffer>print
..part? It appears to be something one would see in a CMD window!
It is. I was testing the command before I put it in a script.
--
Crash

Committed to the search for intraterrestrial intelligence.
Todd Vargo
2014-04-10 21:15:45 UTC
Permalink
Post by Evertjan.
Post by Todd Vargo
This way still works from the command prompt.
notepad /p file.txt
Simply nestle it into a .Run statement to use in a VBScript in order to
print to whatever is the default printer. Unfortunately, I am unaware of
a way to select a different printer port using this method.
Use MSDOS "print".
1 open Start > Control Panel > Devices and Printers.
2 right-click the printer you want to use and select Properties.
3 in the Sharing tab, decide to share the printer
3 assign a share name to it. [myHP]
print /d://myComputerName\myHP F:\myDirectory\myFile.txt
[where myComputerName should be the name you use
and and myHP the actual sharename you invented]
==============================
<http://www.robvanderwoude.com/printfiles.php>
Good reading.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Loading...