Script that defaults printer according to office location for users who move around - terminal server

Heys guys

Ill go straight to the point

We have a terminal server environment where users often access the server from different office locations. And they want their default printer to change according to which office location they are.

So basically I need a script that will:

On startup (login script), Pop up a GUI or a simple pop up asking user to choose which office they are currently on. Once they choose, it defaults to printer according to office

So for example, if office1 then defaults hp1, office2 defaults to kyocera2 and so forth

I have a vb in place that defaults everyone to one printer... Would that be of any help? Can I just edit my current to do what I need to or do I need a totally new script in a totally new language?

Can anyone help me writing this or have a sample?

Thanks
Craig RutherfordAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
kemi67Connect With a Mentor Commented:
If you don't use the select but the if statement, you have to use different variables name for the office and for the printer.
Here you are the modified script.
Option Explicit
Dim objPrinter
dim chooseOffice
dim strOffice
dim strUMG
dim strBP
dim strLH
dim strCF
dim strNL
dim strRC
dim strPrinter
dim chooseOfficePrinter


' ###########################
' #  Office location List   #
' ###########################


strOffice=vbCrLf & "1   Upper Mount Gravatt"  
strOffice=strOffice & vbCrLf &"2   Browns Plains" 
strOffice=strOffice & vbCrLf &"3   Loganholme" 
strOffice=strOffice & vbCrLf &"4   Clayfield" 
strOffice=strOffice & vbCrLf &"5   North Lakes" 
strOffice=strOffice & vbCrLf &"6   Redcliffe" 


' #######################################
' #  Upper Mount Gravatt Printer List   #
' #######################################


strUMG=vbCrLf & "1   UMG - OKI C5300 Ticket Printer"  
strUMG=strUMG & vbCrLf &"2   UMG Canon Doctors" 
strUMG=strUMG & vbCrLf &"3   UMG Canon iP5300 - Debbie" 
strUMG=strUMG & vbCrLf &"4   UMG Canon MP640" 
strUMG=strUMG & vbCrLf &"5   UMG Kyocera" 
strUMG=strUMG & vbCrLf &"6   UMG Lexmark E250dn" 


' #################################
' #  Browns Plains Printer List   #
' #################################


strBP=vbCrLf & "1   Browns Plains Brother MFC-5860CN"  
strBP=strBP & vbCrLf &"2   Browns Plains Canon iP5300" 


' ##############################
' #  Loganholme Printer List   #
' ##############################

strLH=vbCrLf & "1   Loganholme Canon MP640 Front Desk Bottom Tray"  
strLH=strLH & vbCrLf &"2   Loganholme Canon MP640 Front Desk Top Tray" 
strLH=strLH & vbCrLf &"3   Loganholme Canon MP640 TC Bottom Tray" 
strLH=strLH & vbCrLf &"4   Loganholme Canon MP640 TC Top Tray" 


' #############################
' #  Clayfield Printer List   #
' #############################

strCF=vbCrLf & "1   Clayfield Canon MP600R Front Desk"  
strCF=strCF & vbCrLf &"2   Clayfield Canon MP640 - Jackie" 
strCF=strCF & vbCrLf &"3   Clayfield Samsung SCX-6x45" 
strCF=strCF & vbCrLf &"4   Clayfield Samsung Tray 2" 



' ###############################
' #  North Lakes Printer List   #
' ###############################

strNL=vbCrLf & "1   North Lakes Canon iP5300"  
strNL=strNL & vbCrLf &"2   North Lakes Canon MP640" 
strNL=strNL & vbCrLf &"3   North Lakes Canon MX850" 



' #############################
' #  Redcliffe Printer List   #
' #############################

strRC=vbCrLf & "1   Redcliffe Canon MP640 - Di"  
strRC=strRC & vbCrLf &"2   Redcliffe Canon MX850" 


' ############################################################
' #  Codes for Input Boxes and Selection - DO NOT TOUCH IT!  #
' ############################################################



chooseOffice= InputBox("Choose Office number " & strOffice)


if chooseOffice =1 Then

    chooseOfficePrinter= InputBox("Choose printer number " & strUMG)

    Select case chooseOfficePrinter
    Case 1
        strPrinter="UMG - OKI C5300 Ticket Printer"
    Case 2
        strPrinter="UMG Canon Doctors"
    Case 3
        strPrinter="UMG Canon iP5300 - Debbie"
    Case 4
        strPrinter="UMG Canon MP640"
    Case 5
        strPrinter="UMG Kyocera"
    Case 6
        strPrinter="UMG Lexmark E250dn"
    End Select
    if chooseOfficePrinter >0 and chooseOfficePrinter <=6 Then

        Set objPrinter = CreateObject("WScript.Network") 
        objPrinter.SetDefaultPrinter strPrinter
    end if
end if

if chooseOffice =2 Then

    chooseOfficePrinter= InputBox("Choose printer number " & strBP)

    Select case chooseOfficePrinter
    Case 1
        strPrinter="Browns Plains Brother MFC-5860CN"
    Case 2
        strPrinter="Browns Plains Canon iP5300"
    End Select
    if chooseOfficePrinter >0 and chooseOfficePrinter <=2 Then

        Set objPrinter = CreateObject("WScript.Network") 
        objPrinter.SetDefaultPrinter strPrinter
    end if
end if


if chooseOffice =3 Then

    chooseOfficePrinter= InputBox("Choose printer number " & strLH)

    Select case chooseOfficePrinter
    Case 1
        strPrinter="Loganholme Canon MP640 Front Desk Bottom Tray"
    Case 2
        strPrinter="Loganholme Canon MP640 Front Desk Top Tray"
    Case 3
        strPrinter="Loganholme Canon MP640 TC Bottom Tray"
    Case 4
        strPrinter="Loganholme Canon MP640 TC Top Tray"
    End Select
    if chooseOfficePrinter >0 and chooseOfficePrinter <=4 Then
        Set objPrinter = CreateObject("WScript.Network") 
        objPrinter.SetDefaultPrinter strPrinter
    end if
end if


if chooseOffice =4 Then

    chooseOfficePrinter= InputBox("Choose printer number " & strCF)

    Select case chooseOfficePrinter
    Case 1
        strPrinter="Clayfield Canon MP600R Front Desk"
    Case 2
        strPrinter="Clayfield Canon MP640 - Jackie"
    Case 3
        strPrinter="Clayfield Samsung SCX-6x45"
    Case 4
        strPrinter="Clayfield Samsung Tray 2"
    End Select
    if chooseOfficePrinter >0 and chooseOfficePrinter <=4 Then

        Set objPrinter = CreateObject("WScript.Network") 
        objPrinter.SetDefaultPrinter strPrinter
    end if
end if


if chooseOffice =5 Then

    chooseOfficePrinter= InputBox("Choose printer number " & strNL)

    Select case chooseOfficePrinter
    Case 1
        strPrinter="North Lakes Canon iP5300"
    Case 2
        strPrinter="North Lakes Canon MP640"
    Case 3
        strPrinter="North Lakes Canon MX850"
    End Select
    if chooseOfficePrinter >0 and chooseOfficePrinter <=3 Then

        Set objPrinter = CreateObject("WScript.Network") 
        objPrinter.SetDefaultPrinter strPrinter
    end if
end if


if chooseOffice =6 Then

    chooseOfficePrinter= InputBox("Choose printer number " & strRC)

    Select case chooseOfficePrinter
    Case 1
        strPrinter="Redcliffe Canon MP640 - Di"
    Case 2
        strPrinter="Redcliffe Canon MX850"
    End Select
    if chooseOfficePrinter >0 and chooseOfficePrinter <=2 Then

        Set objPrinter = CreateObject("WScript.Network") 
        objPrinter.SetDefaultPrinter strPrinter
    end if
end if

Open in new window

0
 
CaptainGibletsCommented:
you could run something like the code i have attached.
Replace the message boxes with your own code to set the default printer.
Option Explicit

Dim strlocation
strlocation=InputBox("Please Select your Printer" & vbCrLf & vbCrLf & "printer1=1" & vbCrLf & "printer2=2")
if strlocation="1" then
	msgbox("You Selected Printer1")
end if
if strlocation="2" then
	msgbox("You selected pritner2")
end if

Open in new window

0
 
kemi67Commented:
Try a VBScript like this.
Create a .vbs file with this code
Option Explicit
Dim objPrinter
dim choose
dim strOffice
dim strPrinter

strOffice=vbCrLf & "1   Office1"  
strOffice=strOffice & vbCrLf &"2   Office2" 
strOffice=strOffice & vbCrLf &"3   Office3" 
strOffice=strOffice & vbCrLf &"4   Office4" 

choose= InputBox("Choose Office number " & strOffice)

Select case choose
Case 1
    strPrinter="Kyocera Mita FS-1800+ KX"
Case 2
    strPrinter="Kyocera Mita FS-3830N"
case 3
    strPrinter="FinePrint"
 case 4
    strPrinter="\\ServerName\PrinterName"
End Select
if choose >0 and choose <=4 Then
    Set objPrinter = CreateObject("WScript.Network") 
    objPrinter.SetDefaultPrinter strPrinter
end if

Open in new window

0
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.

 
Craig RutherfordAuthor Commented:
kemi67

thats fantastic, thanks. It worked perfectly on my Windows 7 pc. Although, I have just transferred the file to my windows server 2008 x64 and tried, and it doesn't default :(

ill investigate
0
 
Craig RutherfordAuthor Commented:
I have found that if my current terminal server default printer is set to a redirected printer (a local printer redirected to the TS via RDP), then the script will not default to any other printer.
If the current default printer is a network or locally installed printer, script works fine

Any idea whats happening?
0
 
kiwistagCommented:
Would any target-specific GPO's help? There some good filtering options for setting rules on certain GPO's.
0
 
kemi67Commented:
Try to see if there is a policy conflict
Check here
http://social.technet.microsoft.com/Forums/en-US/winserverTS/thread/2a6944a1-d1cb-492c-b413-75dcbe7dad9b/

In particular, check these GPOs setting

computer config | policies |admin templates | windows components | terminal services | terminal server | printer redirection:
do not set default client printer to be default printer in a session
redirect only the default client printer
0
 
Craig RutherfordAuthor Commented:
kemi67: that was the one... that made the script work perfectly, thank you so much.

Now the last thing im trying to achieve, just because the users are very needy and they asked me for that :-) , I would like to add a little bit more to the script.

At the moment, the script is set to if you select office1, it selects printer1 and so forth... I'd like it to, after selecting the office, it will provide me with the printer list (that I can manually type) for the selected office, they select the number, and that will default to that printer

Im going to try that myself, not sure if Ill make it, but if you read this before I'd appreciate the help :)

Thanks
0
 
Craig RutherfordAuthor Commented:
I think Ive got it... ill try it and will let you know

will then paste the code so you can have a quick look

cheers
0
 
Craig RutherfordAuthor Commented:
Ok, I've done it. It works beautifully

Although, there's a bug... if I choose option 3, then option 4 for example, it defaults to the printer 4, but instead of ending there, it also pops up with the case 4 InputBox. Same thing if I choose option 1 then option 2, it pops up with the case 2 InputBox

I'm not experienced with scripting at all, so, what am I missing?


Thanks
Option Explicit
Dim objPrinter
dim choose
dim strOffice
dim strUMG
dim strBP
dim strLH
dim strCF
dim strNL
dim strRC
dim strPrinter


' ###########################
' #  Office location List   #
' ###########################


strOffice=vbCrLf & "1   Upper Mount Gravatt"  
strOffice=strOffice & vbCrLf &"2   Browns Plains" 
strOffice=strOffice & vbCrLf &"3   Loganholme" 
strOffice=strOffice & vbCrLf &"4   Clayfield" 
strOffice=strOffice & vbCrLf &"5   North Lakes" 
strOffice=strOffice & vbCrLf &"6   Redcliffe" 


' #######################################
' #  Upper Mount Gravatt Printer List   #
' #######################################


strUMG=vbCrLf & "1   UMG - OKI C5300 Ticket Printer"  
strUMG=strUMG & vbCrLf &"2   UMG Canon Doctors" 
strUMG=strUMG & vbCrLf &"3   UMG Canon iP5300 - Debbie" 
strUMG=strUMG & vbCrLf &"4   UMG Canon MP640" 
strUMG=strUMG & vbCrLf &"5   UMG Kyocera" 
strUMG=strUMG & vbCrLf &"6   UMG Lexmark E250dn" 


' #################################
' #  Browns Plains Printer List   #
' #################################


strBP=vbCrLf & "1   Browns Plains Brother MFC-5860CN"  
strBP=strBP & vbCrLf &"2   Browns Plains Canon iP5300" 


' ##############################
' #  Loganholme Printer List   #
' ##############################

strLH=vbCrLf & "1   Loganholme Canon MP640 Front Desk Bottom Tray"  
strLH=strLH & vbCrLf &"2   Loganholme Canon MP640 Front Desk Top Tray" 
strLH=strLH & vbCrLf &"3   Loganholme Canon MP640 TC Bottom Tray" 
strLH=strLH & vbCrLf &"4   Loganholme Canon MP640 TC Top Tray" 


' #############################
' #  Clayfield Printer List   #
' #############################

strCF=vbCrLf & "1   Clayfield Canon MP600R Front Desk"  
strCF=strCF & vbCrLf &"2   Clayfield Canon MP640 - Jackie" 
strCF=strCF & vbCrLf &"3   Clayfield Samsung SCX-6x45" 
strCF=strCF & vbCrLf &"4   Clayfield Samsung Tray 2" 



' ###############################
' #  North Lakes Printer List   #
' ###############################

strNL=vbCrLf & "1   North Lakes Canon iP5300"  
strNL=strNL & vbCrLf &"2   North Lakes Canon MP640" 
strNL=strNL & vbCrLf &"3   North Lakes Canon MX850" 



' #############################
' #  Redcliffe Printer List   #
' #############################

strRC=vbCrLf & "1   Redcliffe Canon MP640 - Di"  
strRC=strRC & vbCrLf &"2   Redcliffe Canon MX850" 


' ############################################################
' #  Codes for Input Boxes and Selection - DO NOT TOUCH IT!  #
' ############################################################



choose= InputBox("Choose Office number " & strOffice)

Select case choose

Case 1
Case 2
case 3
case 4
case 5
case 6

End Select
if choose =1 Then

choose= InputBox("Choose printer number " & strUMG)

Select case choose
Case 1
    strPrinter="UMG - OKI C5300 Ticket Printer"
Case 2
    strPrinter="UMG Canon Doctors"
Case 3
    strPrinter="UMG Canon iP5300 - Debbie"
Case 4
    strPrinter="UMG Canon MP640"
Case 5
    strPrinter="UMG Kyocera"
Case 6
    strPrinter="UMG Lexmark E250dn"
End Select
if choose >0 and choose <=6 Then

    Set objPrinter = CreateObject("WScript.Network") 
    objPrinter.SetDefaultPrinter strPrinter
end if
end if

if choose =2 Then

choose= InputBox("Choose printer number " & strBP)

Select case choose
Case 1
    strPrinter="Browns Plains Brother MFC-5860CN"
Case 2
    strPrinter="Browns Plains Canon iP5300"
End Select
if choose >0 and choose <=2 Then

    Set objPrinter = CreateObject("WScript.Network") 
    objPrinter.SetDefaultPrinter strPrinter
end if
end if


if choose =3 Then

choose= InputBox("Choose printer number " & strLH)

Select case choose
Case 1
    strPrinter="Loganholme Canon MP640 Front Desk Bottom Tray"
Case 2
    strPrinter="Loganholme Canon MP640 Front Desk Top Tray"
Case 3
    strPrinter="Loganholme Canon MP640 TC Bottom Tray"
Case 4
    strPrinter="Loganholme Canon MP640 TC Top Tray"
End Select
if choose >0 and choose <=4 Then
    Set objPrinter = CreateObject("WScript.Network") 
    objPrinter.SetDefaultPrinter strPrinter
end if
end if


if choose =4 Then

choose= InputBox("Choose printer number " & strCF)

Select case choose
Case 1
    strPrinter="Clayfield Canon MP600R Front Desk"
Case 2
    strPrinter="Clayfield Canon MP640 - Jackie"
Case 3
    strPrinter="Clayfield Samsung SCX-6x45"
Case 4
    strPrinter="Clayfield Samsung Tray 2"
End Select
if choose >0 and choose <=4 Then

    Set objPrinter = CreateObject("WScript.Network") 
    objPrinter.SetDefaultPrinter strPrinter
end if
end if


if choose =5 Then

choose= InputBox("Choose printer number " & strNL)

Select case choose
Case 1
    strPrinter="North Lakes Canon iP5300"
Case 2
    strPrinter="North Lakes Canon MP640"
Case 3
    strPrinter="North Lakes Canon MX850"
End Select
if choose >0 and choose <=3 Then

    Set objPrinter = CreateObject("WScript.Network") 
    objPrinter.SetDefaultPrinter strPrinter
end if
end if


if choose =6 Then

choose= InputBox("Choose printer number " & strRC)

Select case choose
Case 1
    strPrinter="Redcliffe Canon MP640 - Di"
Case 2
    strPrinter="Redcliffe Canon MX850"
End Select
if choose >0 and choose <=2 Then

    Set objPrinter = CreateObject("WScript.Network") 
    objPrinter.SetDefaultPrinter strPrinter
end if
end if

Open in new window

0
 
kemi67Commented:
Did you try this second script?
0
 
kemi67Commented:
Black-Knight, any news from my last script?
0
 
Craig RutherfordAuthor Commented:
Hey mate, im sorry, i thought i had closed this question. The script worked like a charm, its up and running without any difficulties. Thank you very much for your help.
0
 
Craig RutherfordAuthor Commented:
ty
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.