![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | VBScript to print on secondary printer I have a script that goes out to the web, retrieves a web page, saves it on the desktop and prints it. This works great with the default printer but I need it to print on a secondary printer without changing the default. Any ideas? The only line that was changed from the working version is the one after 'enable this to print'. 'define vars dim officePrinter officePrinter = "\\server\printer name" url = "http://mysite.com" path = "C:\Users\Store\Desktop\temp.txt" 'instantiate Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") Set fso = CreateObject("Scripting.FileSystemObject") Set txtfile = fso.OpenTextFile(path, 2, True) Set oWS = WScript.CreateObject("WScript.Shell") 'make request xmlhttp.open "GET", url, false xmlhttp.send "" 'wait for response xmlhttp.waitForResponse() 'if status is 200, then it's OK if xmlhttp.status = 200 then txtfile.WriteLine(xmlhttp.responseText) txtfile.Close 'enable this to print oWS.Run "notepad.exe /p " + path + " " + officePrinter 'enable this to just display 'oWS.Run "notepad.exe " + path else 'popup bad response, or just omit to end WScript.Echo("bad response") end if 'destroy objects. I'm not sure this is necessary Set txtfile = nothing Set xmlhttp = nothing Set oWS = nothing Set fso = nothing |
My System Specs![]() |
| | #2 (permalink) |
| | Re: VBScript to print on secondary printer Just found out that Windows is such a POS system that it doesn't allow scripts to print to anything but the default printer. Unbelievable. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: VBScript to print on secondary printer On Dec 16, 7:24*pm, drhowarddrfine <robbel...@xxxxxx> wrote: Quote: > Just found out that Windows is such a POS system that it doesn't allow > scripts to print to anything but the default printer. *Unbelievable. script. Then you can send your print job to the default and after the job is done, it can be swapped back to the original. For example, this code fragment saves the default printer's name and then sets the default to another printer (assuming it is installed on that machine) ... Set oWMISrvc = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\.\root\cimv2") Set cDfltPrinter = oWMISrvc.ExecQuery _ ("Select * from Win32_Printer Where Default = True") For Each objPrinter in cDfltPrinter if objPrinter.Default then sDfltPtr = objPrinter.Name Next sAltPrtrName = "\\\\server\\printer" Set cPrinter = oWMISrvc.ExecQuery _ ("Select * from Win32_Printer Where Name = '" _ & sAltPrtrName & "'") For Each oPrtr in cPrinter oPrtr.SetDefaultPrinter() Next Set cDfltPrinter = oWMISrvc.ExecQuery _ ("Select * from Win32_Printer Where Default = True") For Each objPrinter in cDfltPrinter if objPrinter.Default then sNewDfltPtr = objPrinter.Name Next wsh.echo "Default was", sOldDfltPtr wsh.echo "Default is now", sNewDfltPtr Just reverse the process to restore the original default after you send the print job. SOme error detection is probably in order, but I leave that to the you to work out. Tom Lavedas *********** http://there.is.no.more/tglbatch/ |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| [MS Word Macro] VBscript flag image to not print it | VB Script | |||
| HTML and VBscript printer management page | VB Script | |||
| Powershell Wrapper Script Problems - Trying to Call PowershellExchange 2007 Commands from Secondary Language (Like VBScript) | PowerShell | |||
| Vista Can't Print to Win2K shared printer-Test Print disappears fr | Vista networking & sharing | |||
| Re: Print Shop won't print using laser printer | Vista print fax & scan | |||