Solved

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

Posted on 2011-02-15
15
749 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:Black-Knight
15 Comments
 
LVL 6

Expert Comment

by:CaptainGiblets
ID: 34895146
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
 
LVL 7

Expert Comment

by:kemi67
ID: 34895177
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
 
LVL 14

Expert Comment

by:Dhiraj Mutha
ID: 34895328
0
 

Author Comment

by:Black-Knight
ID: 34895429
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
 

Author Comment

by:Black-Knight
ID: 34895474
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
 
LVL 6

Expert Comment

by:kiwistag
ID: 34895488
Would any target-specific GPO's help? There some good filtering options for setting rules on certain GPO's.
0
 
LVL 7

Expert Comment

by:kemi67
ID: 34895539
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Black-Knight
ID: 34903113
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
 

Author Comment

by:Black-Knight
ID: 34903170
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
 

Author Comment

by:Black-Knight
ID: 34903351
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
 
LVL 7

Accepted Solution

by:
kemi67 earned 500 total points
ID: 34904293
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
 
LVL 7

Expert Comment

by:kemi67
ID: 34915671
Did you try this second script?
0
 
LVL 7

Expert Comment

by:kemi67
ID: 34949214
Black-Knight, any news from my last script?
0
 

Author Comment

by:Black-Knight
ID: 35820895
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
 

Author Closing Comment

by:Black-Knight
ID: 35820911
ty
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now