472,102 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,102 software developers and data experts.

Creating Printer Port in VB

I need to create a file printer port. I can do it using the PRNADMIN.DLL
like so:

Public Sub CreateFilePort(ByVal FilePath As String)
Dim PRNADMIN As New PRNADMINLib.PrintMaster
Dim port As New PRNADMINLib.Port
port.PortName = FilePath
port.PortType = 3 'Standard Local Port
PRNADMIN.PortAdd(port)
End Sub

Is there any way I can do it without using this COM assembly?
Feb 23 '07 #1
4 10015
WMI will do it.

You could also use the Microsoft scripting runtime (is also COM but will
almost allways be installed)

There might also be a command line way with PRINTUI.DLL

"Terry Olsen" <to******@hotmail.comwrote in message
news:O1**************@TK2MSFTNGP05.phx.gbl...
>I need to create a file printer port. I can do it using the PRNADMIN.DLL
like so:

Public Sub CreateFilePort(ByVal FilePath As String)
Dim PRNADMIN As New PRNADMINLib.PrintMaster
Dim port As New PRNADMINLib.Port
port.PortName = FilePath
port.PortType = 3 'Standard Local Port
PRNADMIN.PortAdd(port)
End Sub

Is there any way I can do it without using this COM assembly?

Feb 23 '07 #2
I've searched through WMI but only found Win32_Printer and
Win32_TCPIPPrinterPort, neither will let me add the kind of port that I
want. Do you know what WMI class will let me add the port?

The PRNADMIN.DLL, according to its documentation, is a wrapper around
PRINTUI.DLL. I tried to figure out how to add the port directly with
PRINTUI.DLL but was unsuccessful there as well.

Ideally, I'd like to be able to do it using WMI or Win32Api, that way I
don't have to rely on an external DLL.

"Michael M." <no****@mike.comwrote in message
news:O%****************@TK2MSFTNGP03.phx.gbl...
WMI will do it.

You could also use the Microsoft scripting runtime (is also COM but will
almost allways be installed)

There might also be a command line way with PRINTUI.DLL

"Terry Olsen" <to******@hotmail.comwrote in message
news:O1**************@TK2MSFTNGP05.phx.gbl...
>>I need to create a file printer port. I can do it using the PRNADMIN.DLL
like so:

Public Sub CreateFilePort(ByVal FilePath As String)
Dim PRNADMIN As New PRNADMINLib.PrintMaster
Dim port As New PRNADMINLib.Port
port.PortName = FilePath
port.PortType = 3 'Standard Local Port
PRNADMIN.PortAdd(port)
End Sub

Is there any way I can do it without using this COM assembly?


Feb 24 '07 #3
I am sure I gave you the WMI code for this arounf 10 days ago Tery. If it
wasn't you then it was another user

--
Newbie Coder
(It's just a name)
Feb 24 '07 #4
You didn't give me code, you gave me links to WMI reference pages. I've
searched through all those pages. I used the WMI Code Creator extensively to
search for anything related to adding a printer port but came up empty. If
you have a specific class for me to look at, i'd appreciate it.

I did, however, get it to work using the AddPortEx API call, though this
call is "obsolete" according to MSDN. Here's the code:

<StructLayout(LayoutKind.Sequential)_
Public Structure PORT_INFO_1
Dim pPortName As String
End Structure

Public Declare Function AddPortEx Lib "winspool.drv" Alias "AddPortExA"
(ByVal pName As String, ByVal pLevel As Integer, ByRef lpBuffer As
PORT_INFO_1, ByVal pMonitorName As String) As Integer

Dim p1 As PORT_INFO_1
p1.pPortName = "C:\PrinterFile.txt"
API.apiAddPortEx(Nothing, 1, p1, "Local Port")

Now I need to figure out how to delete a port. There is a DeletePort API
call, but it throws up a dialog for the user. I want to delete the port
without user intervention. There isn't a DeletePortEx call that I can find
(as a counterpart to the AddPortEx call).

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
>I am sure I gave you the WMI code for this arounf 10 days ago Tery. If it
wasn't you then it was another user

--
Newbie Coder
(It's just a name)


Feb 25 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Lizard King | last post: by
1 post views Thread by Bow Hunter | last post: by
reply views Thread by Soon Lee | last post: by
3 posts views Thread by Joca | last post: by
reply views Thread by Gustavo | last post: by
reply views Thread by H. Williams | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.