?
Solved

Default Printer by site or location

Posted on 2004-08-19
3
Medium Priority
?
341 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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

This program is used to assist in finding and resolving common problems with wireless connections.
If you try to migrate from Elastix to Issabel, you will face a lot of issues. These problems are inevitable but fortunately, you can fix them. In the guide below, I will explain how I performed the migration while keeping all data and successfully t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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…

601 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