VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Sending Raw Data to the Printer Port in VB

by Daniel S. Soper (9 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (13 Votes)

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.

Inputs
Whatever raw data you want to send to the printer port. This data should be in string format.
Assumes
Using this code bypasses Windows' built in print spooler, and sends only raw data to the printer port.
Code Returns
Nothing.
Side Effects
None known. Tested on Windows 98 and Windows 2000 Professional.
API Declarations
None. =-]

Rate Sending Raw Data to the Printer Port in VB

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

Download this snippet    Add to My Saved Code

Sending Raw Data to the Printer Port in VB Comments

No comments have been posted about Sending Raw Data to the Printer Port in VB. Why not be the first to post a comment about Sending Raw Data to the Printer Port in VB.

Post your comment

Subject:
Message:
0/1000 characters