+ Post New Thread
Results 1 to 6 of 6
Scripts Thread, Printer chooser in Coding and Web Development; This is really dirty but knocked it up quickly because we had laptop users wanting to print stuff etc. In ...
  1. #1

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,229
    Thank Post
    1,056
    Thanked 1,066 Times in 623 Posts
    Rep Power
    739

    Printer chooser

    This is really dirty but knocked it up quickly because we had laptop users wanting to print stuff etc.
    In a larger school this is really no good but in a small school some may find it handy.

    Anyone with some scripting skills will be able to reverse engineer this to suit their own requirements.
    And the reason I had to call a .CMD to call a .VBS is that I could not get AutoIT to call a .VBS correctly - like I said it's messy but works.
    When I get time I'll knock something up thats better and easier to edit.

    Attached is a quick snapshot of what the combo box looks like.


    You will need to edit it to your own requirements but all source stuff is here:

    The AutoIT code:
    Code:
    ; AutoIt Version:  	3.10
    ; Language:        	English
    ; Platform:        	WinXP
    ; Author:          	Matt 
    ; Script Function: 	Printer Selector For Users When Using Laptops
    ; Version:			1b
    ; Date:				Ver 1b March 2009
    
    ; RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder
    
    Dim $COL_ICT = "Colour - ICT Room"
    Dim $MON_ICT = "Mono - ICT Room"
    Dim $COL_JB = "Colour - Junior Block"
    Dim $COL_PPL = "Colour - Pre Prep Library"
    Dim $COL_MBSR = "Colour - Main Building Staff Room"
    Dim $COL_DT = "Colour - D&T"
    Dim $COL_MR = "Colour - Maths Room"
    Dim $COL_PPSR = "Colour - Pre Prep Staff Room"
    Dim $COL_SPARE = "Colour - Science"
    
    #include <GuiConstants.au3>
    
    GUICreate("Select Printer", 255, 66, (@DesktopWidth - 55) / 2, (@DesktopHeight - 66) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
    
    $Combo_1 = GUICtrlCreateCombo("Colour - ICT Room", 20, 10, 200, 21)
    GUICtrlSetData(-1, "Colour - ICT Room|Mono - ICT Room|Colour - Junior Block|Colour - Pre Prep Library|Colour - Main Building Staff Room|Colour - D&T|Colour - Maths Room|Colour - Pre Prep Staff Room|Colour - Science|")
    $ok = GUICtrlCreateButton("Select Printer To Install", 40, 40, 120, 20)
    GUISetState()
    While 1
    	$bpress = GUIGetMsg()
    	Select
    		Case $bpress = $GUI_EVENT_CLOSE
    			ExitLoop
    		Case $bpress = $ok
    			$site = GUICtrlRead($Combo_1)
    			If $site = $COL_JB Then
    				Run("RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder")
    				sleep(2000)
    				Run(@ScriptDir & "\col_jb.cmd")
    				SplashTextOn("Installing Printer.....","Installing Printer - please wait, this may take a while." & @CRLF & "Only attempt to print once printer appears.","-1","50","-1","-1",0,"","","")
    				Sleep(10000)
    				SplashOff()
    				Exit
    			ElseIf $site = $COL_ICT Then
    				Run("RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder")
    				sleep(2000)
    				Run(@ScriptDir & "\col_ICT.cmd")
    				SplashTextOn("Installing Printer.....","Installing Printer - please wait, this may take a while." & @CRLF & "Only attempt to print once printer appears.","-1","50","-1","-1",0,"","","")
    				Sleep(10000)
    				SplashOff()
    				Exit
    			ElseIf $site = $COL_SPARE Then
    				Run("RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder")
    				sleep(2000)
    				Run(@ScriptDir & "\col_SPARE.cmd")
    				SplashTextOn("Installing Printer.....","Installing Printer - please wait, this may take a while." & @CRLF & "Only attempt to print once printer appears.","-1","50","-1","-1",0,"","","")
    				Sleep(10000)
    				SplashOff()
    				Exit
    			ElseIf $site = $MON_ICT Then
    				Run("RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder")
    				sleep(2000)
    				Run(@ScriptDir & "\MON_ICT.cmd")
    				SplashTextOn("Installing Printer.....","Installing Printer - please wait, this may take a while." & @CRLF & "Only attempt to print once printer appears.","-1","50","-1","-1",0,"","","")
    				Sleep(10000)
    				SplashOff()
    				Exit
    			ElseIf $site = $COL_PPL Then
    				Run("RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder")
    				sleep(2000)
    				Run(@ScriptDir & "\col_ppl.cmd")
    				SplashTextOn("Installing Printer.....","Installing Printer - please wait, this may take a while." & @CRLF & "Only attempt to print once printer appears.","-1","50","-1","-1",0,"","","")
    				Sleep(10000)
    				SplashOff()
    				Exit
    			ElseIf $site = $COL_MBSR Then
    				Run("RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder")
    				sleep(2000)
    				Run(@ScriptDir & "\col_mbsr.cmd")
    				SplashTextOn("Installing Printer.....","Installing Printer - please wait, this may take a while." & @CRLF & "Only attempt to print once printer appears.","-1","50","-1","-1",0,"","","")
    				Sleep(10000)
    				SplashOff()
    				Exit
    			ElseIf $site = $COL_DT Then
    				Run("RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder")
    				sleep(2000)
    				Run(@ScriptDir & "\col_dt.cmd")
    				SplashTextOn("Installing Printer.....","Installing Printer - please wait, this may take a while." & @CRLF & "Only attempt to print once printer appears.","-1","50","-1","-1",0,"","","")
    				Sleep(10000)
    				SplashOff()
    				Exit
    			ElseIf $site = $COL_MR Then
    				Run("RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder")
    				sleep(2000)
    				Run(@ScriptDir & "\col_mr.cmd")
    				SplashTextOn("Installing Printer.....","Installing Printer - please wait, this may take a while." & @CRLF & "Only attempt to print once printer appears.","-1","50","-1","-1",0,"","","")
    				Sleep(10000)
    				SplashOff()
    				Exit
    			EndIf
    	EndSelect
    WEnd
    Example of a VBS

    Code:
    Set WshNetwork = CreateObject("WScript.Network")
    On Error Resume Next
    Set oPrinters = WshNetwork.EnumPrinterConnections
            For i = 1 to oPrinters.Count - 1 Step 2
                  WshNetwork.RemovePrinterConnection oPrinters.Item(i)
            Next
    Set WshNetwork = CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection "\\Server\SamsungC_Design_and_Tech"
    WshNetwork.SetDefaultPrinter "\\Server\SamsungC_Design_and_Tech"
    Example of the Batch

    Code:
    "p:\misc\printer selector\col_jb.vbs"
    Attached Images Attached Images

  2. #2

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,374
    Thank Post
    625
    Thanked 951 Times in 653 Posts
    Blog Entries
    2
    Rep Power
    318
    Launching a VBscript should be as easy as:

    Code:
    C:\Windows\System32\WScript.exe "C:\path\to\file.vbs"
    Also... can you not do all that VB stuff from within AutoIt using some COM components/objects rubbish or other?
    Last edited by Ric_; 6th March 2009 at 03:00 PM. Reason: language

  3. #3

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,229
    Thank Post
    1,056
    Thanked 1,066 Times in 623 Posts
    Rep Power
    739
    I tried a

    Runwait('cscript.exe "c:\path\file.vbs"')

    But Noooooooo - flashed up but nothing. Also replaced cscript with wscript -same !!

  4. #4

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,229
    Thank Post
    1,056
    Thanked 1,066 Times in 623 Posts
    Rep Power
    739
    Quote Originally Posted by webman View Post
    Launching a VBscript should be as easy as:

    Also... can you not do all that VB stuff from within AutoIt using some COM components/objects rubbish or other?
    Yes, but I was in a hurry !! [ And I already had the VBS stuff in place for other stuff so thought - what the hell - recycle !! ]

  5. #5

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    114
    I tried a Runwait
    ShellExecuteWait(filename, parameters) worked for me last time I wanted to run an EXE with a bunch of CL switches.

  6. #6

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,229
    Thank Post
    1,056
    Thanked 1,066 Times in 623 Posts
    Rep Power
    739
    Quote Originally Posted by PiqueABoo View Post
    ShellExecuteWait(filename, parameters) worked for me last time I wanted to run an EXE with a bunch of CL switches.
    I'll try that after the weekend.
    When I did the Runwait with the cscript.exe blah blah\file.vbs - I got a DOS box flashed up but it didn't run. I'll keep my fingers crossed with the ShellExecute - [ first time I have see in, just checking my help file now !! ]
    This just proves the diverstsy of the language - it's obvious how comfortable I've been over the years with a set of functions that have worked for me.

SHARE:
+ Post New Thread

Similar Threads

  1. Printer repair: Direct Printer Solutions
    By contink in forum Recommended Suppliers
    Replies: 0
    Last Post: 20th January 2009, 11:26 AM
  2. Smart Printer and Microsoft Office Printer
    By jamin100 in forum How do you do....it?
    Replies: 1
    Last Post: 26th February 2008, 11:15 PM
  3. Replies: 13
    Last Post: 20th February 2008, 04:29 PM
  4. Install printer without the printer.
    By kennysarmy in forum Hardware
    Replies: 9
    Last Post: 23rd January 2008, 11:42 AM
  5. Replies: 6
    Last Post: 23rd June 2007, 08:44 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •