Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Default Printer by site or location

Posted on 2004-08-19
3
Medium Priority
?
339 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 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

During and after that shift to cloud, one area that still poses a struggle for many organizations is what to do with their department file shares.
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

782 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