Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


VBScript : Read default printer and connect lptx

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,885
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBScript : Read default printer and connect lptx
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 VBScript : Read default printer and connect lptx - 8/1/2003 12:10:30 PM   
  Soulshepard

 

Posts: 1
Score: 0
Joined: 8/1/2003
From: Netherlands
Status: offline
Made to get your dos apps printing made easy.
suggestions allways welcome..

---cut&paste---

option explicit

'This script will read the default printer installed on an 2000/XP workstation.
'then takes this value and makes a local lpt1 and 2 capture to that port.
'version 1.2
'
'By : Soulshepard@hotmail.com
'

'supress errors
ON ERROR RESUME NEXT

'preferences.
'
dim WshNetwork, WshShell, arrPrn, strDescr, arrPort, strPort, strMsg, strPrn

' Connect to shell
'
Set WshShell = WScript.CreateObject("WScript.Shell")

' Read printer info from registry
'
strPrn = WshShell.RegRead("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")

' Format printer info
'
arrPrn = Split( strPrn, ",", -1, vbTextCompare )
strDescr = arrPrn(0)
arrPort = Split( arrPrn(2), ":", -1, vbTextCompare )
strPort = arrPort(0)

'use the value resulted as the default printer for LPT1 and 2
'
Set WshNetwork = WScript.CreateObject("WScript.Network")

WshNetwork.RemovePrinterConnection "LPT1"
WshNetwork.RemovePrinterConnection "LPT2"

WshNetwork.AddPrinterConnection "LPT1" , strDescr
WshNetwork.AddPrinterConnection "LPT2" , strDescr


' In case of debug, Display the result
'
'strMsg = vbCrLf & "Default printer is " _
' & strDescr & " on " & strPort
'WScript.Echo strMsg

---EOF---
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBScript : Read default printer and connect lptx Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts