Solved

Default Printer by site or location

Posted on 2004-08-19
3
279 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Issue with  IP address/conflict 10 87
Linksys 4 port wireless router 62 48
Hyper-V VM not connected 1 88
EIGRP STUB 19 46
When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

863 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

19 Experts available now in Live!

Get 1:1 Help Now