Link to home
Start Free TrialLog in
Avatar of RobertoFreemano
RobertoFreemanoFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Get IP address of network printer (once mapped)? VB.NET 2003 (pref) / 2010 Exp

Hi Experts,

Is it possible to get a network printers IP Address once mapped to my machine?

e.g.
1. I map printer through run \\print server\printername
2. I would like to (either) specifiy a single printer through its UNC path or
just interigate all mapped printers and have them show in textbox on my WINDFORM.

I'm getting tired having to delv through printer properties for port data :(

I searched through several web articals:

http://www.robvanderwoude.com/2kprintcontrol.html
http://www.robvanderwoude.com/batchcommands.html#PRNCFG
http://technet.microsoft.com/en-us/library/cc754632.aspx

... but i guess i need an expert - right ;)

I found the following code below, but I'm not sure how it make it work with what i'm trying to do.

Thanks,
Rob
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ' Example of how to use this subroutine:
        AddNetworkPrinter("HP LaserJet 1320 PCL 6", "//myserver/Printer", True, True)
    End Sub

    ''' <summary>
    ''' Adds a Network Printer to the computer
    ''' </summary>
    ''' <param name="printerName">Name of the Printer you'd like to add</param>
    ''' <param name="networkPath">The path of the networked printer</param>
    ''' <param name="useExistingDriver">Don't overwrite existing driver</param>
    ''' <param name="setDefaultPrinter">Set as the default printer</param>
    ''' <remarks></remarks>

    Public Shared Sub AddNetworkPrinter(ByRef printerName As String, ByRef networkPath As String, _
     Optional ByRef useExistingDriver As Boolean = 0, Optional ByRef setDefaultPrinter As Boolean = 0)

        Dim cmdToSend As String = "rundll32 printui.dll,PrintUIEntry /in /m " & Chr(34) & printerName & Chr(34) & " /f " & networkPath
        If useExistingDriver Then cmdToSend += " /u" '  /u = use the existing printer driver if it's already installed
        If setDefaultPrinter Then cmdToSend += " /y" '  /y = set printer as the default
        Shell(cmdToSend, AppWinStyle.Hide) ' execute the command

    End Sub

Open in new window

Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

The title and description do not match. Do you want to get the IP of connected printer or do you want to connect to a network printer?
Avatar of RobertoFreemano

ASKER

Hi CodeCruiser,

Sorry for the confusion: Get IP of connected printer please CodeCruiser but if possible connect to a network printer too ;)
1. Get IP of connected printer please
2. if possible, connect to a network printer too ;)
Gosh! It's a bit over my head ...
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks CodeCruiser,

I have a few ideas but will need to take into the office to test... brb ;)
are you wanting to just get the ip address?

just command prompt

ping UNCprintername

and it should return the ip address of said printer... if within the same subnet/network
... might not be able to do this across domains...
Thanks CC ;)
Glad to help :-)