How to Open Cash Drawer using VB.NET

Submitted by: 
Visitors have accessed this post 20128 times.

I just want to share with you the code that I have found on the internet on how to open a Cash Drawer using VB.NET.

I am in no way claim this code as my own work. I want to share this with you because there’s a lot of question on the internet on how to open a Cash Drawer on VB.NET.

The code will simply open the cash drawer using either the LPT port or COM port.

Use the following code and test it if it will work on the brand of your cash drawer.

  1. Private Sub OpenCashDrawer()
  2. Dim intFileNo As Integer = FreeFile()
  4. 'Use this code if you are using LPT Port
  5. FileOpen(1, "c:\escapes.txt", OpenMode.Output)
  6. PrintLine(1, Chr(27) & "p" & Chr(0) & Chr(25) & Chr(250))
  7. FileClose(1)
  9. Shell("print /d:lpt1 c:\escapes.txt", vbNormalFocus)
  11. 'Use this code if you are using COM Port
  12. FileOpen(1, AppDomain.CurrentDomain.BaseDirectory & "open.txt", OpenMode.Output)
  13. PrintLine(1, Chr(27) & Chr(112) & Chr(0) & Chr(25) & Chr(250))
  14. FileClose(1)
  16. Shell("print /d:com1 open.txt", AppWinStyle.Hide)
  17. End Sub



Thanks for sharing
What would i have to change in this code for vb6

Thanks a lot

tnx for the share. . .
this is just what i search for . . .

thank you.

What do I have to do to this code to open a cash drawer if the POS printer is connected trough a USB port?

'Use this code if you are using COM Port
FileOpen(1, AppDomain.CurrentDomain.BaseDirectory & "open.txt", OpenMode.Output)
PrintLine(1, Chr(27) & Chr(112) & Chr(0) & Chr(25) & Chr(250))

Shell("print /d:com1 open.txt", AppWinStyle.Hide)

please explain what inside in open.txt or escape.txt where it should be located and purpose of it.

can u post what inside in the escapes.txt and open.txt files?

thank you very much! ur post help me a lot :)

Hi I can't find what inside escapes.txt and open.txt files.
Can u post it please?


Hi guys,

I need your help to know a way to select a particular cash drawer when two of them are connected in parallel via a splitter to a Star POS printer.

Any help will be highly appreciated!


Can any one please help me to know what is Open.txt or escape.txt
what written inside them. where it should be located.what is the purpose of those.
i found above code on lot of places but no body ever explain about opent.txt and escape.txt.
can any body help.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.