Search Tools Links Login

Sending Raw Data to the Printer Port in VB


Visual Basic 6, or VB Classic

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

Inputs

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

Assumptions

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

Returns

Nothing.

Side Effects

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

API Declarations

None. =-]

Code

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: 156 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.