Search Tools Links Login

Sending Raw Data to the Printer Port in VB

Have you ever tried to send raw data to a printer port (LPT1 for example) using Visual Basic without using VB's printer object or an outside DLL or API? If you have then you know that it is virtually impossible because Visual Basic cannot directly access any system devices. This very simple code demonstrates how to use an undocumented feature of VB's 'OPEN' statement to allow direct access to the printer port as if it were a file. Accessing system devices as if they were a file is a method that was built into the old DOS-based versions of Basic, but until now I was unaware that this functionality still exists in Visual Basic. This method even works in Windows 2000, which is supposed to block direct port access for security purposes.

Original Author: Daniel S. Soper


Whatever raw data you want to send to the printer port. This data should be in string format.


Using this code bypasses Windows' built in print spooler, and sends only raw data to the printer port.



Side Effects

None known. Tested on Windows 98 and Windows 2000 Professional.

API Declarations

None. =-]


Dim printString as String
printString = "Sample Raw Data"
Open "LPT1:" For Output Access Write As #1
Print #1, printString
Close #1

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 104 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.