mattx Posted March 6, 2009 Posted March 6, 2009 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: ; 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 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 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 "p:\misc\printer selector\col_jb.vbs"
webman Posted March 6, 2009 Posted March 6, 2009 (edited) Launching a VBscript should be as easy as: 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? Edited March 6, 2009 by Ric_ language
mattx Posted March 6, 2009 Author Posted March 6, 2009 I tried a Runwait('cscript.exe "c:\path\file.vbs"') But Noooooooo - flashed up but nothing. Also replaced cscript with wscript -same !!
mattx Posted March 6, 2009 Author Posted March 6, 2009 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 !! ]
PiqueABoo Posted March 7, 2009 Posted March 7, 2009 I tried a Runwait ShellExecuteWait(filename, parameters) worked for me last time I wanted to run an EXE with a bunch of CL switches.
mattx Posted March 7, 2009 Author Posted March 7, 2009 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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now