Solved

script to select default printer

Posted on 2007-03-27
15
218 Views
Last Modified: 2010-07-27
Hi all,

background

2003 server

i am trying to get a script to offer the user a choice of which printer to have as their default depending on which office they happen to be. i think i am almost there but it does not work.

Option Explicit
Dim objNetwork, sPrintPath, sLocate
set objNetwork = CreateObject("WScript.Network")
sLocate = InputBox("Which office are you in? Type 'B', 'M', 'N', 'R', 'T'.")
Select Case sLocate
      Case "B"
            sPrintPath = "\\jjfox1\BombayChicken"
      Case "M"
            sPrintPath = "\\jjfox1\MeatSamosa"
      Case "N"
            sPrintPath = "\\Newcastles\Navratan"
      Case "R"
            sPrintPath = "\\jjfox1\Raita"
      Case "T"
            sPrintPath = "\\jjfox1\tandoorichicken"
objNetwork.SetDefaultPrinter sPrintPath
WScript.quit
End Select

any help greatly appreciated
thanks
gareth
0
Comment
Question by:gareth629
[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
  • 7
  • 7
15 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18800241
What's happening with the code now?
I would modify it to this:


Option Explicit
Dim objNetwork, sPrintPath, sLocate
set objNetwork = CreateObject("WScript.Network")
Main()
wscript.quit

Sub Main

sLocate = InputBox("Which office are you in? Type 'B', 'M', 'N', 'R', 'T'.")
If sLocate <> "B" and sLocate <> "M" and sLocate <> "N" and sLocate <> "R" and sLocate <> "T" Then
  wscript.echo "You must select a valid choice!"
  Main
End If
Select Case sLocate
      Case "B"
            sPrintPath = "\\jjfox1\BombayChicken"
      Case "M"
            sPrintPath = "\\jjfox1\MeatSamosa"
      Case "N"
            sPrintPath = "\\Newcastles\Navratan"
      Case "R"
            sPrintPath = "\\jjfox1\Raita"
      Case "T"
            sPrintPath = "\\jjfox1\tandoorichicken"
objNetwork.SetDefaultPrinter sPrintPath
WScript.quit
End Select
End Sub
0
 
LVL 15

Expert Comment

by:MarkMichael
ID: 18803042
Can you not add the default printer automatically depending on which %logonserver% they are authenticating to?
0
 

Author Comment

by:gareth629
ID: 18806467
hi

SirBounty

currently the script does bring up the question and allows the entry of a choice however it does not actually change the default.
thanks, i will try the change and see what happens.

Mark

sorry shoul have been clearer on the question. i have a complete citrix enironment and ony thin terms on the desktop.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:gareth629
ID: 18814932
Hi SirBounty

i have copied and pasted your script and tried it.

for some reason only 'T' works.

security is set correctly on all the printers as i do have access to each printer etc

any ideas?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18815446
above the select case, place this: (perhaps the response needs to be stripped of any white space)

msgbox "|" & sLocate & "|"
Select Case sLocate
      Case "B"
            sPrintPath = "\\jjfox1\BombayChicken"
      Case "M"
            sPrintPath = "\\jjfox1\MeatSamosa"
      Case "N"
            sPrintPath = "\\Newcastles\Navratan"
      Case "R"
            sPrintPath = "\\jjfox1\Raita"
      Case "T"
            sPrintPath = "\\jjfox1\tandoorichicken"
objNetwork.SetDefaultPrinter sPrintPath
0
 

Author Comment

by:gareth629
ID: 18815826
hi sirbounty,

i have played about with the order of the case " " positions.

it is only ever the last in the list (currently Case"T") which works. if i move B to the last in the order B will work

thanks
gareth
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18815857
Try my last post please, and let me know what it returns...you might also adjust the input line to read:

sLocate = Trim(InputBox("Which office are you in? Type 'B', 'M', 'N', 'R', 'T'."))
0
 

Author Comment

by:gareth629
ID: 18815970
sorry

i did try your last post but still not working correctly. working as per my last post.

also

tried the new input line and still the same.

sorry about this mate.


0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18815993
Right - but I need to know what was in that msgbox when you ran it?
0
 

Author Comment

by:gareth629
ID: 18816042
when msgbox "|" & sLocate & "|" was in the script the initial question box was no different but after selecting and pressing 'ok' a new box popped up with INI for example on it.

when using the new input there was no change from  original.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18816070
Use this sub main...

Sub Main

sLocate = ucase(trim(InputBox("Which office are you in? Type 'B', 'M', 'N', 'R', 'T'.")))
If sLocate <> "B" and sLocate <> "M" and sLocate <> "N" and sLocate <> "R" and sLocate <> "T" Then
  wscript.echo "You must select a valid choice!"
  Main
End If
Select Case sLocate
      Case "B"
            sPrintPath = "\\jjfox1\BombayChicken"
      Case "M"
            sPrintPath = "\\jjfox1\MeatSamosa"
      Case "N"
            sPrintPath = "\\Newcastles\Navratan"
      Case "R"
            sPrintPath = "\\jjfox1\Raita"
      Case "T"
            sPrintPath = "\\jjfox1\tandoorichicken"
objNetwork.SetDefaultPrinter sPrintPath
WScript.quit
End Select
End Sub
0
 

Author Comment

by:gareth629
ID: 18816109
no change. can only select the last in the list
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18816161
Ack! I see the problem... sorry about that.
Use 'this' sub...

Sub Main
sLocate = ucase(trim(InputBox("Which office are you in? Type 'B', 'M', 'N', 'R', 'T'.")))
If sLocate <> "B" and sLocate <> "M" and sLocate <> "N" and sLocate <> "R" and sLocate <> "T" Then
  wscript.echo "You must select a valid choice!"
  Main
End If
Select Case sLocate
      Case "B"
            sPrintPath = "\\jjfox1\BombayChicken"
      Case "M"
            sPrintPath = "\\jjfox1\MeatSamosa"
      Case "N"
            sPrintPath = "\\Newcastles\Navratan"
      Case "R"
            sPrintPath = "\\jjfox1\Raita"
      Case "T"
            sPrintPath = "\\jjfox1\tandoorichicken"
  End Select
objNetwork.SetDefaultPrinter sPrintPath
wscript.quit
End Sub
0
 

Author Comment

by:gareth629
ID: 18842047
Hi SirBounty,

that's the badger!!!!

thanks very mcuh for your help. working like a dream now
gareth
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18842548
:^)
Happy to help!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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