1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Modify map printer script

Discussion in 'Scripting & Programming' started by SimonV, Dec 16, 2003.

  1. SimonV

    SimonV Petabyte Poster Administrator

    6,616
    149
    228
    I think this one is for our resident script monkey Phil, if you remember a while ago I was implementing a script to map printers in a classroom using this script:

    [code:1:b3250e8458]Set WshNetwork = CreateObject("WScript.Network")
    PrinterPath = "\\itdept\canons20"
    PrinterDriver = "Test Printer"
    WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
    WshNetwork.SetDefaultPrinter "\\itdept\canons20"[/code:1:b3250e8458]

    What I'd like to be able to add a line to this script that will enable me to exclude a computer by name so that the script is not applied to that PC. I know I could do this by moving the computer into another OU but then that adds other complications and more work.

    Any help would great.

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

    Phil Gigabyte Poster

    1,680
    7
    87
    Si the best way of doing this if you are using Group Policy to apply the script would be to put the computers that you want to apply the script to in a group then add that group to the security tab for the gpo, add the apply permission to it and remove the apply permission for Domain Computers.

    However if you really want to script it you could do the following

    [code:1:5f46cf2c27]
    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 = "COMPUTERNAME" then

    Set WshNetwork = CreateObject("WScript.Network")
    PrinterPath = "\\itdept\canons20"
    PrinterDriver = "Test Printer"
    WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
    WshNetwork.SetDefaultPrinter "\\itdept\canons20"

    end if
    [/code:1:5f46cf2c27]

    change the COMPUTERNAME to the computername you wish to exclude and bear in mind that it is case sensetive.
     
    Certifications: MCSE:M & S MCSA:M CCNA CNA
    WIP: 2003 Upgrade, CCNA Upgrade
  3. SimonV

    SimonV Petabyte Poster Administrator

    6,616
    149
    228
    Thanks for the comments Phil, I have alot of other settings in the group policy that I do wish to apply to this one PC but not the mapping of the Printer. I was thinking of creating another policy just for this one PC but I really wanted to keep it all in one to make it easier to manage.

    I guess like you say I could do it the other way around and remove the printer mapping from the first policy and create a second just for the printer and only apply it to the group of PC's that doesnt include the one PC. It just seems a little messy. :silly

    Do you think it would be better done that way rather than by script and why? :scratch

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

    Phil Gigabyte Poster

    1,680
    7
    87
    I think it gives more flexibility in future, it's much easier to add and remove members of a group than to have to modify a script if your requirements change.
     
    Certifications: MCSE:M & S MCSA:M CCNA CNA
    WIP: 2003 Upgrade, CCNA Upgrade
  5. SimonV

    SimonV Petabyte Poster Administrator

    6,616
    149
    228
    For now Ive made the change to the script as a quick fix but I hear what your saying Phil and agree with you. When I get some free time next year I'll look at this in more depth, but I just dont have the time at the minute.

    Thanks again for the help.

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

    Phil Gigabyte Poster

    1,680
    7
    87
    No probs mate, it's your call :) I just supply the options :twisted: :deal
     
    Certifications: MCSE:M & S MCSA:M CCNA CNA
    WIP: 2003 Upgrade, CCNA Upgrade

Share This Page

Loading...