[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

WMI TCPIPPrinterport object for Windows 2000?

Posted on 2007-08-10
6
Medium Priority
?
1,361 Views
Last Modified: 2013-11-26
I have an upcoming project that requires an overhaul of the entire IP scheme.  My biggest hurdle is handling some 40 network printers that my 300 clients are accessing via IP address.  What I would like to do is create a DNS entry for every printer, write a script to automatically map all of the clients to the hostname, and then simply update the IP addresses in DNS.  I have written a VBScript to do this using the Win32_TCPIPPrinterport WMI object.  Unfortunately, this object doesn't exist for Windows 2000.  Does anyone know of a way to script this for 2000, or atleast a way to access the Standard TCP/IP information via WMI in 2000?  Thanks.
0
Comment
Question by:logo29a
  • 2
  • 2
5 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 19680610
If you want to map to the hostname without specifically creating the TCP/IP port, would you be able to just use
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\server\printer"

That way, when you change the IP Address, you could just use
objNetwork.RemovePrinterConnection "\\server\printer"

Otherwise, if you still need to create the TCP/IP port in Windows 2000, try PRNADMIN.DLL:
HOW TO: Programmatically Create a Printer and Printer Port by Using PrinterAdmin (Prnadmin.dll) with a Visual Basic Script in Microsoft Windows 2000
http://support.microsoft.com/kb/321025

P.S. AddWindowsPrinterConnection: http://msdn2.microsoft.com/en-us/library/zsdh7hkb.aspx
RemovePrinterConnection: http://msdn2.microsoft.com/en-us/library/tsbh2yy7.aspx

Regards,

Rob.
0
 
LVL 1

Author Comment

by:logo29a
ID: 19683378
Rob,
Thanks for the reply.  I'd much rather modify an existing port than create a new one.  Besides, I'd still need to be able to delete the old port and assign the new one.  I'm guessing that if there's a way to find the old port by IP address then I could simply alter that address as opposed to deleting it and creating a new one.
0
 
LVL 1

Author Comment

by:logo29a
ID: 19684641
Increased points.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 1000 total points
ID: 19714366
Sorry for the late reply, I've been away for a few days.  This looks like a complicated process, but here's something that I found as a batch file, and I have converted it to VBS today.  It's not finished yet, and it may take me some time to get it to work properly, and also as a printer replacing script.

First, this is a calling VBS file that runs the main script:
'==============
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strComputer = "VM09790RINGW2K"
strCommand = "wscript " & objFSO.GetFile(Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Remove_Printer_Port_And_Add_Printer_In_Win2K_Using_PrnAdmin_dll.vbs").ShortPath & " " & strComputer
objShell.Run strCommand, 1, False
Set objShell = Nothing
'==============

Then, make sure you have the following files in the the same folder (all from the Win2K Resource Kit):
drvmgr.vbs
portmgr.vbs
prncfg.vbs
prnmgr.vbs

Then, register prnadmin.dll on the client machine (also from the Win2K Resource Kit).

Then, call this script Remove_Printer_Port_And_Add_Printer_In_Win2K_Using_PrnAdmin_dll.vbs in the same folder:
'============
'Source: http://www.robvanderwoude.com/files/addipprn_nt.txt
Set objFSO = CreateObject("Scripting.FileSystemObject")
If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
      strArgs = ""
      If WScript.Arguments.Count > 0 Then
            For intCount = 0 To WScript.Arguments.Count - 1
                  If strArgs = "" Then
                        strArgs = WScript.Arguments.Item(intCount)
                  Else
                        strArgs = strArgs & " " & WScript.Arguments.Item(intCount)
                  End If
            Next
      End If
    strPath = objFSO.GetFile(Wscript.ScriptFullName).ShortPath
    strCommand = "%comspec% /k cscript  " & strPath & " " & strArgs
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run(strCommand), 1, True
    Wscript.Quit
End If

'WScript.Echo "Script is now running using: " & Right(WScript.FullName, 11)

Set objShell = CreateObject("Wscript.Shell")
Set objProcess = objShell.Environment("Process")
strOS = objProcess("OS")
If strOS = "Windows_NT" Then
      '==========================================================================='
      '                                                                           '
      '    Modify the following lines; no double quotes for PortIP                '
      '                                                                           '
      '    The values for PrnType and TargetOS can be found in the INF file       '
      '    that comes with the (extracted) printer driver.                        '
      '                                                                           '
      '==========================================================================='
      PrnName = """HP LaserJet 2100"""
      PrnShort = """HP LaserJet 2100"""
      PrnType = """HP LaserJet 2100"""
      DrvPath = """\\server\share\Drivers\Kyocera\FS-3820N\W2K"""
      InfPath = """\\server\share\Drivers\Kyocera\FS-3820N\W2K\oemsetup.inf"""
      PortIP = "172.16.1.207"
      TargetOS = """Windows 2000"""
      
      '==========================================================================='
      '                                                                           '
      '       End of adjustments                                                  '
      '                                                                           '
      '==========================================================================='
      
      ' Check command line arguments
      If WScript.Arguments.Count > 0 Then
            strPC = WScript.Arguments.Item(0)
            If Ping(strPC) = False Then
                  WScript.Echo "Computer " & strPC & " is unavailable."
                  Show_Syntax
            Else
                  ' Check if the required VBScripts are available in the current directory
                  boolContinue = True
                  arrFiles = Array("prncfg.vbs", "prnmgr.vbs", "drvmgr.vbs", "portmgr.vbs")
                  For Each strFile In arrFiles
                        If objFSO.FileExists(strFile) = False Then boolContinue = False
                  Next
                  If boolContinue = False Then
                        WScript.Echo "One of the required VBS files can not be found."
                        Show_Syntax
                  Else
                        ' Check if the printer was installed already
                        Set objExec = objShell.Exec("cmd /c CSCRIPT.EXE //NoLogo prnmgr.vbs -l -c \\" & strPC & " | FIND.EXE /I " & PrnShort & " >NUL && " &_
                              "ECHO A printer named " & PrnShort & " already exists on " & strPC)
                        While objExec.Status = 0
                        Wend
                        strResult = objExec.StdOut.ReadAll
                        WScript.Echo strResult
                        If InStr(strResult, "A printer named ") > 0 Then
                              ' The printer exists
                              WScript.Echo "Now we need to remove the printer and printer port."
                                                      
                              ' Check if the printer port was installed already
                              Set objExec = objShell.Exec("cmd /c CSCRIPT.EXE //NoLogo portmgr.vbs -l -c \\" & strPC & " | FIND.EXE /I ""IP_" & PortIP & """ >NUL && " &_
                                    "ECHO TCP/IP Printer Port " & PortIP & " already exists on " & strPC)
                              While objExec.Status = 0
                              Wend
                              strResult = objExec.StdOut.ReadAll
                              WScript.Echo strResult
                              If InStr(strResult, "TCP/IP Printer Port ") > 0 Then
                                    ' The printer port exists
                                    WScript.Echo "The printer port already exists. We will not need to create it."
                              Else
                                    ' The printer port does not exist
                                    WScript.Echo "The printer port does not exist. We will need to create it."
                              End If


                              ' ====== RE-INSTALL THE PRINTER =============
                              '==============
                              ' Install the driver
                              strCommand = "CSCRIPT.EXE //NoLogo drvmgr.vbs  -a -c \\" & strPC & " -p " & DrvPath & " -i " & InfPath & " -v " & TargetOS & " -m " & PrnType & " -t Intel"
                              objShell.Run strCommand, 1, True
                              ' Install the local IP print port, type raw, SNMP disabled
                              strCommand = "CSCRIPT.EXE //NoLogo portmgr.vbs -a -c \\" & strPC & " -p IP_" & PortIP & " -h " & Port_IP & " -t raw -n 9100 -md"
                              objShell.Run strCommand, 1, True
                              ' Install the local printer with the driver and port we just installed
                              strCommand = "CSCRIPT.EXE //NoLogo prnmgr.vbs  -a -c \\" & strPC & " -b " & PrnName & " -m " & PrnType & " -r IP_" & Port_IP
                              objShell.Run strCommand, 1, True
                              ' Configure the local printer as not shared and not published in Active Directory
                              strCommand = "CSCRIPT.EXE //NoLogo prncfg.vbs  -s -b \\" & strPC & "\" & PrnShort & " -published -shared"
                              objShell.Run strCommand, 1, True
                              '==============

                              
                              
                        Else
                              ' The printer does not exist
                              WScript.Echo "The printer does not exist. There is nothing to change."
                        End If
                  End If
            End If
      Else
            WScript.Echo "No arguments were passed to the script."
            Show_Syntax
      End If

Else
      WScript.Echo "This script must be run on a Windows machine."
      Show_Syntax
End If

Sub Show_Syntax()
      strMessage =  "AddIPPrn.bat,  Version 1.01 for Windows 2000 with Server Resource Kit"
      strMessage = strMessage & VbCrLf & "Install a (hard coded) local IP printer %PrnShort% on a remote computer"
      strMessage = strMessage & VbCrLf
      strMessage = strMessage & VbCrLf & "Usage:  ADDIPPRN.BAT   computername  [ /L ]"
      strMessage = strMessage & VbCrLf
      strMessage = strMessage & VbCrLf & "Where:  ""computername"" is the computer on which the printer should be installed"
      strMessage = strMessage & VbCrLf & "        ""/L""           logs the results in {printername}_{computername}.log"
      strMessage = strMessage & VbCrLf & "                       (default is display on screen)"
      strMessage = strMessage & VbCrLf
      strMessage = strMessage & VbCrLf & "Notes:  [1] You need to modify the first couple of lines from this batch file"
      strMessage = strMessage & VbCrLf & "            to install your own printer, port and driver. You may then want"
      strMessage = strMessage & VbCrLf & "            to save the modified batch file as {printername}.bat."
      strMessage = strMessage & VbCrLf & "        [2] This batch file requires drvmgr.vbs, portmgr.vbs, prnmgr.vbs and"
      strMessage = strMessage & VbCrLf & "            prncfg.vbs from the Windows 2000/2003 Server Resource Kit; these"
      strMessage = strMessage & VbCrLf & "            scripts must all be located in the current directory."
      strMessage = strMessage & VbCrLf & "        [3] These VBScripts require PRNADMIN.DLL from the Resource Kit to be"
      strMessage = strMessage & VbCrLf & "            installed on the computer that runs the scripts."
      strMessage = strMessage & VbCrLf
      strMessage = strMessage & VbCrLf & "Written by Rob van der Woude"
      strMessage = strMessage & VbCrLf & "http://www.robvanderwoude.com"
      strMessage = strMessage & VbCrLf
      WScript.Echo strMessage
End Sub

Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function
'============

Regards,

Rob.
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20482735
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month17 days, 17 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question