Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Default Printer by site or location

Posted on 2004-08-19
3
Medium Priority
?
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
jamesreddy earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.
If you’re involved with your company’s wide area network (WAN), you’ve probably heard about SD-WANs. They’re the “boy wonder” of networking, ostensibly allowing companies to replace expensive MPLS lines with low-cost Internet access. But, are they …
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

719 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