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.Netw ork")
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\Phase 8200DP"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\HP Color LaserJet 4600"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\Canon iR C6800"
WshNwtwork.SetDefaultPrint er "\\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("wscr ipt.Networ k")
Computer = WshNetwork.ComputerName
If Computer = "EdDono" then 'This is the exact compter name
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\Phase 8200DP"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\HP Color LaserJet 4600"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\Canon iR C6800"
WshNetwork.SetDefaultPrint er "HP DeskJet 612C" ' This is the local printer
Else
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\Phase 8200DP"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\HP Color LaserJet 4600"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\Canon iR C6800"
WshNwtwork.SetDefaultPrint er "\\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
--Start Script--
Set WshNetwork = CreateObject("wscript.Netw
WshNetwork.AddWindowsPrint
WshNetwork.AddWindowsPrint
WshNetwork.AddWindowsPrint
WshNwtwork.SetDefaultPrint
--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("wscr
Computer = WshNetwork.ComputerName
If Computer = "EdDono" then 'This is the exact compter name
WshNetwork.AddWindowsPrint
WshNetwork.AddWindowsPrint
WshNetwork.AddWindowsPrint
WshNetwork.SetDefaultPrint
Else
WshNetwork.AddWindowsPrint
WshNetwork.AddWindowsPrint
WshNetwork.AddWindowsPrint
WshNwtwork.SetDefaultPrint
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.ComputerN ame)
Select Case strComputer
Case "EDDONO"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\Phase 8200DP"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\HP Color LaserJet 4600"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\Canon iR C6800"
WshNetwork.SetDefaultPrint er "HP DeskJet 612C" ' This is the local printer
Case "OTHERPC"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\Phase 8200DP"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\HP Color LaserJet 4600"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\Canon iR C6800"
WshNetwork.SetDefaultPrint er "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
strComputer = ucase(WshNetwork.ComputerN
Select Case strComputer
Case "EDDONO"
WshNetwork.AddWindowsPrint
WshNetwork.AddWindowsPrint
WshNetwork.AddWindowsPrint
WshNetwork.SetDefaultPrint
Case "OTHERPC"
WshNetwork.AddWindowsPrint
WshNetwork.AddWindowsPrint
WshNetwork.AddWindowsPrint
WshNetwork.SetDefaultPrint
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
ASKER
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
Thanks again...Phil
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Case Else
msgbox strComputer & " was not accounted for."
Thanks...Phil
ASKER
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.
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.
ASKER
Excellent...I am going to try out the solutions and let you know how it goes.
Thanks,
Phil
Thanks,
Phil
ASKER
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.Netw ork")
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\Phaser 8200DP"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\HP Color LaserJet 4600"
WshNetwork.AddWindowsPrint erConnecti on "\\urcwc-dc\Canon iR C6800"
wshNetwork.SetDefaultPrint er "\\urcwc-dc\Phaser 8200DP"
strComputer = ucase(WshNetwork.ComputerN ame)
Select Case strComputer
Case "EDDONO"
WshNetwork.SetDefaultPrint er "HP DeskJet 612C" ' This is the local printer
Case "MRSDONO"
WshNetwork.SetDefaultPrint er "HP OfficeJet 6200 series" ' This is the local printer
Case "GREGSONYVIO"
WshNetwork.SetDefaultPrint er "HP OfficeJet 5500 series" ' This is the local printer
'Case Else
'msgbox strComputer & " was not accounted for."
End Select
--End Script--
--Start Script--
Set WshNetwork = CreateObject("Wscript.Netw
WshNetwork.AddWindowsPrint
WshNetwork.AddWindowsPrint
WshNetwork.AddWindowsPrint
wshNetwork.SetDefaultPrint
strComputer = ucase(WshNetwork.ComputerN
Select Case strComputer
Case "EDDONO"
WshNetwork.SetDefaultPrint
Case "MRSDONO"
WshNetwork.SetDefaultPrint
Case "GREGSONYVIO"
WshNetwork.SetDefaultPrint
'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. :^)
Computer = ucase(WshNetwork.ComputerN
If Computer = "EDDONO" then