Link to home
Start Free TrialLog in
Avatar of Phil Rine
Phil Rine

asked on

Mapping default network and local printers

I am currently using the following in a login script for a network running Win 2003 and clients on Win XP Pro.  This script works perfectly as is but I am trying to modify it to determine if there is a local printer and set that one as a default.

--Start Script--
Set WshNetwork = CreateObject("wscript.Network")

WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\Phase 8200DP"
WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\HP Color LaserJet 4600"
WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\Canon iR C6800"

WshNwtwork.SetDefaultPrinter "\\urcwc-dc\Phase 8200DP"
--End Script--

The following is how I modified it but it does not set the local printer as the default.  It seems to go to the else and map the designated network as default.

--Start Script--
Dim WshNetwork
Dim Computer

Set WshNetwork = wscript.CreateObject("wscript.Network")

Computer = WshNetwork.ComputerName

If Computer = "EdDono" then          'This is the exact compter name
WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\Phase 8200DP"
WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\HP Color LaserJet 4600"
WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\Canon iR C6800"
WshNetwork.SetDefaultPrinter "HP DeskJet 612C" '        This is the local printer
Else
WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\Phase 8200DP"
WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\HP Color LaserJet 4600"
WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\Canon iR C6800"
WshNwtwork.SetDefaultPrinter "\\urcwc-dc\Phase 8200DP"
End If

Set WshNetwork = Nothing
Set Computer = Nothing
--End Script--

A few notes:
1. I did not write the original working scipt and am not versed in Visual Basic.
2. When I tested the script, I logged in to the machine using remote desktop.  So I am logging in on another network machine and the remoting to the machine with the local printer and logging in to that.  Could that be the problem?
3. I have double checked the computer name and local printer name for accuracy.
4. I have several other machine with local printers.  How would I modify it to check other machines with different computer names and different local printers.

Any help would be greatly appreciated.
Phil
Avatar of sirbounty
sirbounty
Flag of United States of America image

Try

Computer = ucase(WshNetwork.ComputerName)

If Computer = "EDDONO" then          
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America 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
Avatar of Phil Rine
Phil Rine

ASKER

I see what you are doing but can I still map the network printers along with the local.  Do I need to be sure that the computer names are all caps in each machine?  I am guessing that it may look like the following:

strComputer = ucase(WshNetwork.ComputerName)
Select Case strComputer
  Case "EDDONO"
    WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\Phase 8200DP"
    WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\HP Color LaserJet 4600"
    WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\Canon iR C6800"
    WshNetwork.SetDefaultPrinter "HP DeskJet 612C" '        This is the local printer
  Case "OTHERPC"
     WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\Phase 8200DP"
     WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\HP Color LaserJet 4600"
     WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\Canon iR C6800"
     WshNetwork.SetDefaultPrinter "HP DeskJet 610" '        This is the local printer
  Case Else
     msgbox strComputer & " was not accounted for."
End Select
 
What do I do when I have computers that do not have local printers and only have network printers. Does that go in the Case Else statement?  I only have about 6 pcs with local printers.  Is that too many to use this method?  Thanks very much.  It looks like I am getting close!!!
Phil
Sorry...I forgot to ask you...do I need to error check if a printer is off or down for down reason?
Thanks again...Phil
SOLUTION
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
Robberbaron...I think I get what is going on.  I should do my usual mapping but follow it up by the Select Case statements, correct?   Can you help me understand what this line means?

Case Else
     msgbox strComputer & " was not accounted for."
Thanks...Phil
What does IMO stand for?
IMO = in my opinion

the CASE ELSE
works when no other case matches. is not any of the named computers
msgbox throws up a message box to let you know that the computer the script runs on was not in the list of CASE .....

Its a good testing idea to let you know what the computername returned by the script was.
remove it or comment out  (use ') when you have got it working.
Excellent...I am going to try out the solutions and let you know how it goes.
Thanks,
Phil
Thank you to sirbounty and robberbaron for all of the input.  The following is the final script that worked great.

--Start Script--
Set WshNetwork = CreateObject("Wscript.Network")

WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\Phaser 8200DP"
WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\HP Color LaserJet 4600"
WshNetwork.AddWindowsPrinterConnection "\\urcwc-dc\Canon iR C6800"


wshNetwork.SetDefaultPrinter "\\urcwc-dc\Phaser 8200DP"

strComputer = ucase(WshNetwork.ComputerName)
Select Case strComputer
  Case "EDDONO"
    WshNetwork.SetDefaultPrinter "HP DeskJet 612C" '        This is the local printer
  Case "MRSDONO"
    WshNetwork.SetDefaultPrinter "HP OfficeJet 6200 series" '        This is the local printer
Case "GREGSONYVIO"
    WshNetwork.SetDefaultPrinter "HP OfficeJet 5500 series" '        This is the local printer
  'Case Else
     'msgbox strComputer & " was not accounted for."
End Select
--End Script--
Sorry I've been away.  Glad you got it resolved.  Thanx for the points. :^)