*PHIL* help with a vbs problem

Discussion in 'Scripting & Programming' started by SimonV, Jan 11, 2005.

  1. SimonV
    Honorary Member

    SimonV Petabyte Poster Gold Member

    6,651
    180
    258
    Som time ago you helped me with this vbs code that set a default printer:

    Code:
    Set NIC1 = GetObject("winmgmts://.").InstancesOf("Win32_NetworkAdapterConfiguration") 
    For Each Nic in NIC1 
         IF Nic.IPEnabled THEN 
                  hostname = Nic.DNSHostName 
                      
         End If 
    Next 
    
    if not hostname = "LIBRARY-03" then 
    
    Set WshNetwork = CreateObject("WScript.Network") 
    PrinterPath = "\\library-03\LIBRARY03-HP1100" 
    PrinterDriver = "LIBRARY-03-HP1100" 
    WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver 
    WshNetwork.SetDefaultPrinter "\\library-03\LIBRARY03-HP1100" 
    
    end if 
    Part of the help I needed was to not appy the code to a spacific computer (Library-03 in this example). My question is can this be extended to two named computers and if so how is it acomplished.

    Thanks, Si. :biggrin
     
    Certifications: MOS Master 2003, CompTIA A+, MCSA:M, MCSE
    WIP: Keeping CF Alive...
  2. Phil
    Honorary Member

    Phil Gigabyte Poster

    1,680
    7
    87
    Hi Si,

    if you change the line

    Code:
     if not hostname = "LIBRARY-03" then  
    to

    Code:
     if not hostname = "LIBRARY-03" or "SOME OTHER COMPUTER" then  
    you should be fine.

    HTH
    Phil :)
     
    Certifications: MCSE:M & S MCSA:M CCNA CNA
    WIP: 2003 Upgrade, CCNA Upgrade
  3. SimonV
    Honorary Member

    SimonV Petabyte Poster Gold Member

    6,651
    180
    258
    I get a runtime error, type mismatch: '[string: "PCNAME"]'
     
    Certifications: MOS Master 2003, CompTIA A+, MCSA:M, MCSE
    WIP: Keeping CF Alive...
  4. Phoenix
    Honorary Member

    Phoenix 53656e696f7220 4d6f64

    5,749
    200
    246
    couldnt you create a text file listing the computer names and then loop the script moving on to the next item each time?
    or take the contets of the text file into an array at runtime?
     
    Certifications: MCSE, MCITP, VCP
    WIP: > 0
  5. Phil
    Honorary Member

    Phil Gigabyte Poster

    1,680
    7
    87
    ok, the following should work

    Code:
     
    if not hostname = "LIBRARY-03" then
    if not hostname = "SOME OTHER COMPUTER" then  
    .
    .
    .
    .
    .
    .
    end if
    end if
    
    It's quick and dirty but should work fine, Pheonix is right you could read in a text file.
     
    Certifications: MCSE:M & S MCSA:M CCNA CNA
    WIP: 2003 Upgrade, CCNA Upgrade

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.