Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > VBScript
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 10th, 2004, 01:19 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default Open CMD, NSLookup, enter name, return IP

Hi,

   Thanks in advance for the help, I hope.

   I am writing a script that loops through all the printers on a machine, determines if the printer is an old NDPS printer, and if so, creates an instance of the printer as a Network IP printer.

   I need to open CMD, run NSLookup, enter the printer name value passed by the user in an Input Box, get the resulting IP address, and continue with the new installation using the IP address as the new Port Name.

   I want to use the DNS to look up these values rather than create an array or use an Access database or some other data store since the script would be more dynamic.

   Here is the code so far, if it fits:

'Declare variables
Dim strDefault 'whether this is the default printer
Dim strDeviceID 'what the device name is, and the new name built on
Dim strDriverName 'what driver to use
Dim strPortName 'this will hold the NEW PortName from the InputBox
Dim strComputer 'this computer = "."
Dim strIBoxTitle 'holds the value of the NDPS PortName until the DNS name can be entered for strPortName

'this first part of the script goes out and gets each printer one at a time,
'then loops for the next one.
On Error Resume Next
strComputer = "." '= this computer
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
For Each objItem in colItems
    Wscript.Echo "Default: " & objItem.Default 'gets the default setting for each printer T/F
    Wscript.Echo "DeviceID: " & objItem.DeviceID 'gets the name of the printer model
    Wscript.Echo "DriverName: " & objItem.DriverName 'gets the Windows Driver name
    Wscript.Echo "PortName: " & objItem.PortName 'gets the port name, i.e. USB, LPT, AOC, IP_ etc.

    'pass this info to the variables
    strDefault = objItems.Default
    strDeviceID = objItem.DeviceID
    strDriverName = objItem.DriverName
    'strPortName = objItem.PortName not needed here
    strIBoxTitle = objItem.PortName 'holds this for the input box title

If Left(strIBoxTitle, 6) = "\\AOC\" Then
        strPortName = InputBox("Please enter the DNS Name for " & strIBoxTitle)
        MsgBox "The NSLookup Function will look for this Printer:" & strPortName
        'function to look up IP of strPortName on the DNS server

I NEED CODE HERE...

        'installs printers one at a time IF they are NDPS pritners, otherwise it skips them,
        'installs printers and drivers
        'resets one of the IP printers to the default IF its NDPS predecessor was the default
        'does NOT remove the old NDPS printers
        MsgBox "I will now try to add " & strPortName & " as an IP Printer", vbOkOnly

        Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
        objPrinter.Default = strDefault 'this should override the old printer, if not, add line here to
        'the old printer to Default = False
        objPrinter.DeviceID = strDeviceID & " IP"
        objPrinter.DriverName = strDriverName
        objPrinter.PortName = 'need to create new port name based on table using "IP_XXX.X.X.X"
        objPrinter.Network = True
        objPrinter.Put_

        'installs the proper driver? Not sure if needed.
        'Set objWMIService = GetObject("winmgmts:")
        'Set objDriver = objWMIService.Get("Win32_PrinterDriver")
        'objDriver.Name = strDriverName
        'objDriver.SupportedPlatform = "Windows NT x86"
        'errResult = objDriver.AddPrinterDriver(objDriver)

    Else
        MsgBox strDeviceID & " is not an NDPS Printer", vbOkOnly
    End if
    'loops back for the next printer
Next

Thanks Folks!

mmcdonal
__________________
mmcdonal

Look it up at: http://wrox.books24x7.com
Reply With Quote
  #2 (permalink)  
Old June 15th, 2004, 12:05 PM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,102
Thanks: 0
Thanked 2 Times in 2 Posts
Default

So what you want to do is use VB script to automate the installation of printers... I don't think this can be done.


Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
Reply With Quote
  #3 (permalink)  
Old December 19th, 2006, 04:23 AM
Registered User
 
Join Date: Dec 2006
Location: Singapore, , Philippines.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is there a way for me to identify the IP address of the network printer(s) using C# application.

I have tried the ManagementObjectSearcher Win32_NetworkAdapterConfiguration but I can only see my own ip address.. same with Win32_Printer.

My goal is to programmatically detect the Network Printer’s IP Address or hostnames based on the printer drivers installed in my PC.

    Can .Net do this?


thank you.


Reply With Quote
  #4 (permalink)  
Old December 19th, 2006, 08:40 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Wow, this is an old post. You can do this calling WMI as in my original post. What do you use in C# to call WMI? I am sure it is there. You can use WMI to install printers, contrary to what Hal Levy posted way back then.

mmcdonal
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open a form to enter a new record dstein4d Access VBA 1 August 17th, 2007 12:36 PM
Carriage Return and Enter keys flashster BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 September 13th, 2006 06:38 AM
how to call shell cmd to open exe on clientside? nana Javascript How-To 6 May 25th, 2006 03:23 AM
Return information from cmd to VB HelgeB VB How-To 4 December 1st, 2004 05:34 AM
cmd.qry mohiddin52 Access 0 December 29th, 2003 08:49 AM



All times are GMT -4. The time now is 05:53 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.