Solved

Default Printer by site or location

Posted on 2004-08-19
3
267 Views
Last Modified: 2010-04-11
Hi there,

I was wondering if there is any way I can set some sort of script to change the default printer depending at which site a laptop is connected to.

Let's say a user's main office is in Sydney (10.10.1.x). But he or she travels between sites quite often, IE; Melbourne (10.10.2.x) and Brisbane (10.10.3.x).

I would like for the user to not worry about changing their default printer when arriving at each site. (They somehow keep stuffing things up!)

Can this be done? (Not sure if I have provided enough info)

Cheers
0
Comment
Question by:Fernando
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
jamesreddy earned 500 total points
ID: 11848679
This should do the trick.  You just have to find the registry entry that stores the current IP address:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Option Explicit
DIM RegEntry, ComputerName

RegEntry="HKLM\SYSTEM\CurrentControlSet001\Services\GUID\Parameters\Tcpip"
DhcpIpAddress = ReadRegValue(RegEntry)

if InStr(1,ucase(DhcpIpAddress),"10.10.20.",vbTextCompare) > 0 then call SetPrinter("\\server1\NH2-Laser")
if InStr(1,ucase(DhcpIpAddress),"10.10.10.",vbTextCompare) > 0 then call SetPrinter("\\server2\NH-RM1")
if InStr(1,ucase(DhcpIpAddress),"10.10.30",vbTextCompare) > 0 then call SetPrinter("\\server3\NH-RM3")
'so on and so forth.
wscript.quit

' ***  This subroutine installs and sets the default printer
Sub SetPrinter(ByVal PrinterPath)
  DIM WshNetwork
  Set WshNetwork = CreateObject("WScript.Network")
  WshNetwork.AddWindowsPrinterConnection(PrinterPath)
  WshNetwork.SetDefaultPrinter Printerpath
end sub

' ****  This function returns the data in the registry value
Function ReadRegValue(ByVal RegValue)      
  DIM WSHShell
  Set WSHShell = WScript.CreateObject("WScript.Shell")
  ReadRegValue=""
  On Error Resume Next
  ReadRegValue= WSHShell.RegRead(RegValue)
End Function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The trick for you is to find that GUID ID that stores the values.  The part of the script that reads: HKLM\SYSTEM\CurrentControlSet001\Services\GUID\Parameters\Tcpip, the "GUID" needs to be replaced with the GUID ID of the machine you are writing the script for.

Best thing you can do is run regedit.  Do a search for "DhcpIpAddress" or do a search for the current IP address in the registry.  When it locates the entry, you can see on the left the GUID container that contains the entry and replace "GUID" with that ID.  In other words, in your script, that line should look like the following:

~~~~~~~~~~~~~~~~~~~~
RegEntry="HKLM\SYSTEM\ControlSet001\Services\{5E2571CF-24A5-4641-9AB7-05D47F821B06}\Parameters\Tcpip"
DhcpIpAddress = ReadRegValue(RegEntry)
~~~~~~~~~~~~~~~~~~~~


That'll get her done.  I did a similar script based on PC Name.  But this will do nicely.

Hopefully that helps.

James



0
 

Author Comment

by:Fernando
ID: 11848751
Wow! I will give it a shot and let you know the outcome. Most likely try it out in a few weeks then. Thank you for your help
0
 
LVL 9

Expert Comment

by:jamesreddy
ID: 11849042
We can tweak it if it doesn't work.  I do not know for sure if a vbTextCompare will work on IP addresses, but it should.  It's just a standard character string.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Let’s list some of the technologies that enable smooth teleworking. 
PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now