lfernandes Posted June 3, 2016 Share Posted June 3, 2016 (edited) I'm working on a printer install script and I've got most of the logic down, I just can't figure out why the GUI isn't working in regards to this loop. The script runs, presents a gui for users to type in the print server/printer name and model and then select install or cancel. Works perfectly how I want it to the first time but it gets to the end where it pops up and asks if they want to install another but the previous loop is still running (I think) and that's causing an issue in that it won't work. Here's the GUI code - as much as I think is needed anyway. Of course let me know if you need more. expandcollapse popupFunc PrinterGUI() ; Create a GUI with various controls. Local $GUI = GUICreate("Printer Installer", 275, 225) ; Create 2 buttons for installing and canceling Local $CancelButton = GUICtrlCreateButton("Cancel", 35, 175, 85, 25) Local $InstallButton = GUICtrlCreateButton("Install", 160, 175, 85, 25) ; Create lables for each text box Local $ServerLabel = GUICtrlCreateLabel("Print Server Hostname", 22, 30, 110, 25) Local $PrinterLabel = GUICtrlCreateLabel("Printer Hostname", 47, 70, 85, 25) ; Create input boxes Local $ServerInput = GUICtrlCreateInput("TESTSERVER", 150, 24, 80, 25) Local $PrinterInput = GUICtrlCreateInput("TESTPRINTER", 150, 65, 80, 25) $ServerName = GUICtrlRead($ServerInput) $PrinterName = GUICtrlRead($PrinterInput) ; Create radio buttons and group for printer models GUIStartGroup() $XeroxRadio = GUICtrlCreateRadio("Xerox", 83, 127, 45, 20) GUICtrlSetState(-1, $GUI_CHECKED) $HPRadio = GUICtrlCreateRadio("HP", 164, 127, 45, 20) $PrinterModelRadioGroup = GUICtrlCreateGroup("Printer Model", 57, 105, 165, 55) $PrinterModel = "" ; Display the GUI. GUISetState(@SW_SHOW, $GUI) Local $idMsg = 0 ; Loop until the user exits. While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $CancelButton ExitLoop Case $idMsg = $ServerInput $ServerName = GUICtrlRead($ServerInput) Case $idMsg = $PrinterInput $PrinterName = GUICtrlRead($PrinterInput) Case $idMsg = $XeroxRadio $PrinterModel = "x" Case $idMsg = $HPRadio $PrinterModel = "h" Case $idMsg = $InstallButton Call("BeginInstall") ExitLoop EndSelect WEnd GUIDelete($GUI) EndFunc The BeginInstall() calls one of two other functions depending on if it was an HP or Xerox printer, which calls the "Finish" function that prints a test page and asks if they want to install another - which is also a problem I think as I don't know how to get it to work either. Again, I've got the script working perfectly ONCE, but when I try to come back it fails and I think it's in part to the GUI's while loop doesn't exit after calling BeginInstall(). I'd appreciate any input Edited June 3, 2016 by lfernandes Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted June 3, 2016 Moderators Share Posted June 3, 2016 (edited) @lfernandes try putting this at the top of your script. It will help you narrow down exactly what line of the script it is hanging at. You can then see what the script is waiting for before it can continue. Opt("TrayIconDebug", 1) Edited June 3, 2016 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
lfernandes Posted June 3, 2016 Author Share Posted June 3, 2016 (edited) That was actually super useful, thank you! However, I found that it is getting hung up on the "EndSelect" in the loop. I'm not sure exactly what to do with that. I added an ExitLoop just after the EndSelect but that just makes the whole thing never execute and end instantly. Any ideas? Edited: Had the wrong info about where it was ending. Edited June 3, 2016 by lfernandes Link to comment Share on other sites More sharing options...
Trong Posted June 3, 2016 Share Posted June 3, 2016 Try: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> PrinterGUI() Func PrinterGUI() ; Create a GUI with various controls. Local $GUI = GUICreate("Printer Installer", 275, 225) ; Create 2 buttons for installing and canceling Local $CancelButton = GUICtrlCreateButton("Cancel", 35, 175, 85, 25) Local $InstallButton = GUICtrlCreateButton("Install", 160, 175, 85, 25) ; Create lables for each text box Local $ServerLabel = GUICtrlCreateLabel("Print Server Hostname", 22, 30, 110, 25) Local $PrinterLabel = GUICtrlCreateLabel("Printer Hostname", 47, 70, 85, 25) ; Create input boxes Local $ServerInput = GUICtrlCreateInput("TESTSERVER", 150, 24, 80, 25) Local $PrinterInput = GUICtrlCreateInput("TESTPRINTER", 150, 65, 80, 25) Local $ServerName = GUICtrlRead($ServerInput) Local $PrinterName = GUICtrlRead($PrinterInput) ; Create radio buttons and group for printer models GUICtrlCreateGroup("Printer Model", 57, 105, 165, 55) Local $XeroxRadio = GUICtrlCreateRadio("Xerox", 83, 127, 45, 20) GUICtrlSetState(-1, $GUI_CHECKED) Local $HPRadio = GUICtrlCreateRadio("HP", 164, 127, 45, 20) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group Local $PrinterModel = "" ; Display the GUI. GUISetState(@SW_SHOW, $GUI) While 1 Switch GUIGetMsg() Case $CancelButton, $GUI_EVENT_CLOSE ExitLoop Case $InstallButton $ServerName = GUICtrlRead($ServerInput) $PrinterName = GUICtrlRead($PrinterInput) If GUICtrlRead($XeroxRadio) = $GUI_CHECKED Then $PrinterModel = "x" If GUICtrlRead($HPRadio) = $GUI_CHECKED Then $PrinterModel = "h" BeginInstall($ServerName, $PrinterName, $PrinterModel) ExitLoop EndSwitch WEnd GUIDelete($GUI) EndFunc ;==>PrinterGUI Func BeginInstall($ServerName, $PrinterName, $PrinterModel) MsgBox(0, "Printer Installer", "Server Name: " & $ServerName & @CRLF & "Printer Name: " & $PrinterName & @CRLF & "Printer Model: " & $PrinterModel) EndFunc ;==>BeginInstall Regards, Link to comment Share on other sites More sharing options...
lfernandes Posted June 3, 2016 Author Share Posted June 3, 2016 (edited) Tried that, and I think that's definitely better than what I had but it's still getting hung up, this time at the WEnd. Let me post the final function call I do to see if that helps - begin install calls a model specific install which calls this function: Func Finish() ;_RunDos('RUNDLL32 PRINTUI.DLL,PrintUIEntry /n"' & $PrinterName & '" /k') GUICreate("Finish") Opt("GUICoordMode", 2) Opt("GUIResizeMode", 1) Opt("GUIOnEventMode", 1) Switch MsgBox(4, "Finished", "The printer has been installed and a test page has been sent to the printer. Do you want to install another?") Case 6 GUIDelete() Call("CheckDrivers") Case 7 Exit EndSwitch EndFunc The CheckDrivers function is just a quick function that makes sure the right folder has been copied, then calls PrinterGUI function. I've tried combiniations of removing the GUIDelete and changing the CheckDrivers function to call the PrinterGUI instead but I just can't get it right Edited June 3, 2016 by lfernandes Add more info Link to comment Share on other sites More sharing options...
lfernandes Posted June 3, 2016 Author Share Posted June 3, 2016 I should add, what's weird is that when I click "Yes" to install again, it reloads the GUI but it's missing all the controls except the cancel button. I don't have the slightest clue how that's possible. Link to comment Share on other sites More sharing options...
Trong Posted June 3, 2016 Share Posted June 3, 2016 post full scripts, I'll make it work! Regards, Link to comment Share on other sites More sharing options...
lfernandes Posted June 3, 2016 Author Share Posted June 3, 2016 Wanted to add, just did some testing and it seems when I call the PrinterGUI, the only control that's loading is the first one created - I mentioned before the cancel button but if I change the order the controls are created, whichever is first is at the top. So (I'm guessing here) is it possible I need to release the variables I use for the controls? If so, how does that work? Link to comment Share on other sites More sharing options...
lfernandes Posted June 3, 2016 Author Share Posted June 3, 2016 I'd rather not post the full script because there's a few privacy concerns in regards to network paths, and those calls are kind of irrelevant as they are fully working. It seems to be related to the kind of recursion issue between the PrinterGUI and Finish functions. Of course I don't mean to refuse your help, not at all, I just don't think the calls that do the physical printer installs seem to be related as they are working perfectly and are just small modules. Link to comment Share on other sites More sharing options...
Trong Posted June 3, 2016 Share Posted June 3, 2016 A program to add printers by reading information from the user input contains personal path? The personal information that you can not delete or change? Regards, Link to comment Share on other sites More sharing options...
lfernandes Posted June 3, 2016 Author Share Posted June 3, 2016 It pulls customized drivers from our network shares. I can remove it, I just wanted to avoid it as it didn't seem necessary to help solve the GUI issue. Again, not trying to come off as nasty or anything, just doesn't seem relevant. I'll remove it and post Link to comment Share on other sites More sharing options...
lfernandes Posted June 3, 2016 Author Share Posted June 3, 2016 Here's the full script - I may have missed some comments I left for myself so sorry in advance..lol expandcollapse popup#RequireAdmin #include <Process.au3> #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> ; Hide the AutoIt icon in the workstation's SysTray ;Opt("TrayIconHide", 1) Opt("TrayIconDebug", 1) Global $DriverScriptPath = "C:\Printers\Scripts\Prndrvr.vbs" Global $PrintManagerPath = "C:\Printers\Scripts\Prnmngr.vbs" Global $PrinterName = "" Global $PrinterPath = "" ;Global $ServerName = "" ;Global $PrinterName = "" ;Global $PrinterModel = "" Global $RunAgain = 0 Call("CheckDrivers") If $RunAgain = 0 Then Exit Else Call(PrinterGUI) EndIf Func CheckDrivers() If FileExists("C:\Printers") Then Call("PrinterGUI") Else Call("CreatePrinterFolder") EndIf EndFunc Func PrinterGUI() ; Create a GUI with various controls. Local $GUI = GUICreate("Printer Installer", 275, 225) ; Create 2 buttons for installing and canceling Local $InstallButton = GUICtrlCreateButton("Install", 160, 175, 85, 25) Local $CancelButton = GUICtrlCreateButton("Cancel", 35, 175, 85, 25) ; Create lables for each text box Local $ServerLabel = GUICtrlCreateLabel("Print Server Hostname", 22, 30, 110, 25) Local $PrinterLabel = GUICtrlCreateLabel("Printer Hostname", 47, 70, 85, 25) ; Create input boxes Local $ServerInput = GUICtrlCreateInput("TESTSERVER", 150, 24, 80, 25) Local $PrinterInput = GUICtrlCreateInput("TESTPRINTER", 150, 65, 80, 25) $ServerName = GUICtrlRead($ServerInput) $PrinterName = GUICtrlRead($PrinterInput) ; Create radio buttons and group for printer models GUIStartGroup() $XeroxRadio = GUICtrlCreateRadio("Xerox", 83, 127, 45, 20) GUICtrlSetState(-1, $GUI_CHECKED) $HPRadio = GUICtrlCreateRadio("HP", 164, 127, 45, 20) $PrinterModelRadioGroup = GUICtrlCreateGroup("Printer Model", 57, 105, 165, 55) $PrinterModel = "" ; Display the GUI. GUISetState(@SW_SHOW, $GUI) While 1 Switch GUIGetMsg() Case $CancelButton, $GUI_EVENT_CLOSE ExitLoop Case $InstallButton $ServerName = GUICtrlRead($ServerInput) $PrinterName = GUICtrlRead($PrinterInput) If GUICtrlRead($XeroxRadio) = $GUI_CHECKED Then $PrinterModel = "x" If GUICtrlRead($HPRadio) = $GUI_CHECKED Then $PrinterModel = "h" BeginInstall($ServerName, $PrinterName, $PrinterModel) ExitLoop EndSwitch WEnd GUIDelete($GUI) EndFunc Func CreatePrinterFolder() ; Function to create the local printer folder and copy drivers and scripts over to it DirCreate("C:\Printers\Scripts") DirCopy("REDACTED", "C:\Printers\Drivers\Xerox Drivers") DirCopy("REDACTED", "C:\Printers\Drivers\HP Drivers") FileCopy("C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs", "C:\Printers\Scripts") FileCopy("C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs", "C:\Printers\Scripts") Call("BeginInstall") EndFunc Func BeginInstall($ServerName, $PrinterName, $PrinterModel) ; Function to create the needed variables, create a registry key for the port, restart the print spooler so the registry key (port) is available to prnmngr.vbs, and delete the printer if it already exists $PrinterPath = ("\\" & $ServerName & "\" & $PrinterName) MsgBox($MB_SYSTEMMODAL, "Boom", $PrinterPath) ; Stops print spooler, adds the necessary registry key for the port, and starts the print spooler again _RunDos("NET stop spooler") regwrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Ports", $PrinterPath, "REG_SZ", "") _RunDOS("NET START spooler") ;Deletes the printer if it already exists. RunWait(@COMSPEC & ' /c cscript "' & $PrintManagerPath & '" -d -p "' & $PrinterName & '"') If $PrinterModel = "x" Then Call("XeroxInstall") Else Call("HPInstall") EndIf EndFunc Func XeroxInstall() ;Installs the XEROX driver, first getting the printer model and .inf file, then -h for the path to the .dll Local $XeroxDriverVersion = "Xerox GPD PCL6 V3.5.404.8.0" Local $XeroxDriverPath = "C:\Printers\Drivers\Xerox Drivers\x2UNIVX.inf" ;This line runs the prndrvr.vbs script and installs the requested print driver on the machine. RunWait(@COMSPEC & ' /c cscript "' & $DriverScriptPath & '" -a -m "' & $XeroxDriverVersion & '" -i "' & $XeroxDriverPath & '" -h "C:\Printers\Drivers\Xerox Drivers"') ;This line runs the prnmngr.vbs script and attaches the printer path (port) to the driver and names the resultant printer. RunWait(@COMSPEC & ' /c cscript "' & $PrintManagerPath & '" -a -p "' & $PrinterName & '" -m "' & $XeroxDriverVersion & '" -r "' & $PrinterPath & '"') Call("Finish") EndFunc Func HPInstall() ;Installs the HP driver, first getting the printer model and .inf file, then -h for the path to the .dll Local $HPDriverVersion = "HP Universal Printing PCL 6 (v6.0.0)" Local $HPDriverPath = "C:\Printers\Drivers\HP Drivers\hpcu175u.inf" ;This line runs the prndrvr.vbs script and installs the requested print driver on the machine. RunWait(@COMSPEC & ' /c cscript "' & $DriverScriptPath & '" -a -m "' & $HPDriverVersion & '" -i "' & $HPDriverPath & '" -h "C:\Printers\Drivers\Xerox Drivers"') ;This line runs the prnmngr.vbs script and attaches the printer path (port) to the driver and names the resultant printer. RunWait(@COMSPEC & ' /c cscript "' & $PrintManagerPath & '" -a -p "' & $PrinterName & '" -m "' & $HPDriverVersion & '" -r "' & $PrinterPath & '"') Call("Finish") EndFunc Func Finish() _RunDos('RUNDLL32 PRINTUI.DLL,PrintUIEntry /n"' & $PrinterName & '" /k') GUICreate("Finish") Opt("GUICoordMode", 2) Opt("GUIResizeMode", 1) Opt("GUIOnEventMode", 1) Switch MsgBox(4, "Finished", "The printer has been installed and a test page has been sent to the printer. Do you want to install another?") Case 6 $RunAgain = 1 Case 7 Exit EndSwitch EndFunc Link to comment Share on other sites More sharing options...
AutoBert Posted June 3, 2016 Share Posted June 3, 2016 Try the script without the exitloop in line 75. Link to comment Share on other sites More sharing options...
Trong Posted June 3, 2016 Share Posted June 3, 2016 (edited) Autoit Adding Network Printer I create something simple: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #RequireAdmin Global Const $PrintsPath = @HomeDrive & "\Printers" Global Const $PrintDriversPath = $PrintsPath & "\Drivers" Global Const $PrintScriptsPath = $PrintsPath & "\Scripts" Global Const $PrintDriverScriptPath = $PrintScriptsPath & "\Prndrvr.vbs" Global Const $PrintManagerScriptPath = $PrintScriptsPath & "\Prnmngr.vbs" Global $ServerName, $PrinterName, $PrinterModel, $PrinterPath #Region ### START GUI Global $hGUI = GUICreate("Printer Installer", 417, 136, -1, -1) GUICtrlCreateLabel("Print Server Hostname", 22, 14, 110, 25, BitOR($SS_RIGHT, $SS_CENTERIMAGE)) GUICtrlCreateLabel("Printer Hostname", 47, 46, 85, 25, BitOR($SS_RIGHT, $SS_CENTERIMAGE)) GUICtrlCreateLabel("Printer Model", 64, 80, 66, 17, BitOR($SS_RIGHT, $SS_CENTERIMAGE)) Global $ServerInput = GUICtrlCreateInput("", 150, 16, 136, 21) Global $PrinterInput = GUICtrlCreateInput("", 150, 49, 136, 21) Global $HPRadio = GUICtrlCreateRadio("HP", 231, 76, 45, 20, BitOR($GUI_SS_DEFAULT_RADIO, $BS_VCENTER)) Global $XeroxRadio = GUICtrlCreateRadio("Xerox", 150, 76, 45, 20, BitOR($GUI_SS_DEFAULT_RADIO, $BS_VCENTER)) GUICtrlSetState(-1, $GUI_CHECKED) Global $InstallButton = GUICtrlCreateButton("Install", 304, 15, 101, 57, BitOR($BS_CENTER, $BS_VCENTER)) Global $CancelButton = GUICtrlCreateButton("Cancel", 307, 79, 101, 25, BitOR($BS_CENTER, $BS_VCENTER)) Global $Status = GUICtrlCreateLabel("", 8, 112, 396, 17, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUISetState(@SW_SHOW) #EndRegion ### START GUI GUICtrlSetData($Status, "Checking Drivers Printer Folder...") If Not FileExists($PrintScriptsPath) Then DirCreate($PrintScriptsPath) If Not FileExists($PrintDriversPath) Then DirCreate($PrintDriversPath) If Not FileExists($PrintDriversPath & "\Xerox Drivers") Then GUICtrlSetData($Status, "Copying Xerox Drivers...") DirCopy("REDACTED", $PrintDriversPath & "\Xerox Drivers", 1) ; Replace REDACTED to Xerox Driver Folder EndIf If Not FileExists($PrintDriversPath & "\HP Drivers") Then GUICtrlSetData($Status, "Copying HP Drivers...") DirCopy("REDACTED", $PrintDriversPath & "\HP Drivers", 1) ; Replace REDACTED to HP Driver Folder EndIf If Not FileExists($PrintDriverScriptPath) Then FileCopy(@WindowsDir & "\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs", $PrintsPath & "\Scripts", 1) If Not FileExists($PrintManagerScriptPath) Then FileCopy(@WindowsDir & "\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs", $PrintsPath & "\Scripts", 1) If Not FileExists($PrintsPath) Or Not FileExists($PrintDriversPath) Or Not FileExists($PrintScriptsPath) Or Not FileExists($PrintDriverScriptPath) Or Not FileExists($PrintManagerScriptPath) Then GUICtrlSetData($Status, "Please check the printer driver directory!") Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "Error", "Please check the printer driver directory!" & @CRLF & "Some file or folder does not exist!") EndIf GUICtrlSetData($Status, "") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $CancelButton Exit Case $InstallButton GUICtrlSetData($Status, "") $ServerName = StringReplace(GUICtrlRead($ServerInput), "\\", "") $PrinterName = GUICtrlRead($PrinterInput) $PrinterModel = "HP" If GUICtrlRead($XeroxRadio) = $GUI_CHECKED Then $PrinterModel = "Xerox" If StringStripWS($ServerName, 8) = "" Or StringStripWS($PrinterName, 8) = "" Then MsgBox($MB_ICONWARNING, "o_0", "Please enter printer information!", Default, $hGUI) Else GUICtrlSetData($Status, "Please waiting...") If MsgBox($MB_ICONQUESTION + $MB_OKCANCEL, "Printer Installer", "Are you sure want to install printer: " & $PrinterName & " ?" & @CRLF & "From: " & "\\" & $ServerName & "\" & $PrinterName) = 1 Then GUICtrlSetData($InstallButton, "Installing....") GUICtrlSetState($InstallButton, $GUI_DISABLE) InstallPinter($ServerName, $PrinterName, $PrinterModel) GUICtrlSetState($InstallButton, $GUI_ENABLE) GUICtrlSetData($InstallButton, "Install") EndIf EndIf EndSwitch Sleep(10) WEnd Func InstallPinter($ServerName, $PrinterName, $PrinterModel) If StringStripWS($ServerName, 8) = "" Or StringStripWS($PrinterName, 8) = "" Then Return SetError(1, 0, 0) $PrinterPath = "\\" & $ServerName & "\" & $PrinterName ; Stops print spooler, adds the necessary registry key for the port, and starts the print spooler again GUICtrlSetData($Status, "Stoping spooler service...") RunWait('"' & @ComSpec & '" /c ' & 'NET stop spooler', "", @SW_HIDE) RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Ports", $PrinterPath, "REG_SZ", "") GUICtrlSetData($Status, "Starting spooler service...") RunWait('"' & @ComSpec & '" /c ' & 'NET START spooler', "", @SW_HIDE) ;Deletes the printer if it already exists. GUICtrlSetData($Status, "Tryting Delete the printer if it already exists....") RunWait('"' & @ComSpec & '" /c cscript "' & $PrintManagerScriptPath & '" - d - p "' & $PrinterName & '"') GUICtrlSetData($Status, "Installing " & $PrinterModel & " Printer Driver...") If $PrinterModel = "Xerox" Then ;Installs the XEROX driver, first getting the printer model and .inf file, then -h for the path to the .dll Local $XeroxDriverVersion = "Xerox GPD PCL6 V3.5.404.8.0" Local $XeroxDriverPath = $PrintDriversPath & "\Xerox Drivers\x2UNIVX.inf" ;This line runs the prndrvr.vbs script and installs the requested print driver on the machine. RunWait('"' & @ComSpec & '" /c cscript "' & $PrintDriverScriptPath & '" -a -m "' & $XeroxDriverVersion & '" -i "' & $XeroxDriverPath & '" -h "' & $PrintDriversPath & '\Xerox Drivers"') ;This line runs the prnmngr.vbs script and attaches the printer path (port) to the driver and names the resultant printer. RunWait('"' & @ComSpec & '" /c cscript "' & $PrintManagerScriptPath & '" - a - p "' & $PrinterName & '" - m "' & $XeroxDriverVersion & '" - r "' & $PrinterPath & '"') Else ;Installs the HP driver, first getting the printer model and .inf file, then -h for the path to the .dll Local $HPDriverVersion = "HP Universal Printing PCL 6 (v6.0.0)" Local $HPDriverPath = $PrintDriversPath & "\HP Drivers\hpcu175u.inf" ;This line runs the prndrvr.vbs script and installs the requested print driver on the machine. RunWait('"' & @ComSpec & '" /c cscript "' & $PrintDriverScriptPath & '" - a - m "' & $HPDriverVersion & '" - i "' & $HPDriverPath & '" - h "' & $PrintDriversPath & '\Xerox Drivers"') ;This line runs the prnmngr.vbs script and attaches the printer path (port) to the driver and names the resultant printer. RunWait('"' & @ComSpec & '" /c cscript "' & $PrintManagerScriptPath & '" - a - p "' & $PrinterName & '" - m "' & $HPDriverVersion & '" - r "' & $PrinterPath & '"') EndIf RunWait('"' & @ComSpec & '" /c ' & 'RUNDLL32 PRINTUI.DLL,PrintUIEntry /n"' & $PrinterName & '" /k') GUICtrlSetData($Status, $PrinterName & " printer installed successful!") MsgBox(0, "Finished", $PrinterName & " printer installed successful!", Default, $hGUI) EndFunc ;==>InstallPinter Try it and let me know if it works or not! or your script with fix like AutoBert say: expandcollapse popup#RequireAdmin #include <Process.au3> #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> ; Hide the AutoIt icon in the workstation's SysTray #NoTrayIcon Global $DriverScriptPath = "C:\Printers\Scripts\Prndrvr.vbs" Global $PrintManagerPath = "C:\Printers\Scripts\Prnmngr.vbs" Global $PrinterName = "" Global $PrinterPath = "" If Not FileExists("C:\Printers") Then CreatePrinterFolder() PrinterGUI() Func PrinterGUI() ; Create a GUI with various controls. Local $GUI = GUICreate("Printer Installer", 275, 225) ; Create 2 buttons for installing and canceling Local $InstallButton = GUICtrlCreateButton("Install", 160, 175, 85, 25) Local $CancelButton = GUICtrlCreateButton("Cancel", 35, 175, 85, 25) ; Create lables for each text box Local $ServerLabel = GUICtrlCreateLabel("Print Server Hostname", 22, 30, 110, 25) Local $PrinterLabel = GUICtrlCreateLabel("Printer Hostname", 47, 70, 85, 25) ; Create input boxes Local $ServerInput = GUICtrlCreateInput("TESTSERVER", 150, 24, 80, 25) Local $PrinterInput = GUICtrlCreateInput("TESTPRINTER", 150, 65, 80, 25) $ServerName = GUICtrlRead($ServerInput) $PrinterName = GUICtrlRead($PrinterInput) ; Create radio buttons and group for printer models GUIStartGroup() $XeroxRadio = GUICtrlCreateRadio("Xerox", 83, 127, 45, 20) GUICtrlSetState(-1, $GUI_CHECKED) $HPRadio = GUICtrlCreateRadio("HP", 164, 127, 45, 20) $PrinterModelRadioGroup = GUICtrlCreateGroup("Printer Model", 57, 105, 165, 55) $PrinterModel = "" ; Display the GUI. GUISetState(@SW_SHOW, $GUI) While 1 Switch GUIGetMsg() Case $CancelButton, $GUI_EVENT_CLOSE Exit Case $InstallButton $ServerName = GUICtrlRead($ServerInput) $PrinterName = GUICtrlRead($PrinterInput) If GUICtrlRead($XeroxRadio) = $GUI_CHECKED Then $PrinterModel = "x" If GUICtrlRead($HPRadio) = $GUI_CHECKED Then $PrinterModel = "h" BeginInstall($ServerName, $PrinterName, $PrinterModel) EndSwitch WEnd GUIDelete($GUI) EndFunc ;==>PrinterGUI Func CreatePrinterFolder() ; Function to create the local printer folder and copy drivers and scripts over to it DirCreate("C:\Printers\Scripts") DirCopy("REDACTED", "C:\Printers\Drivers\Xerox Drivers") DirCopy("REDACTED", "C:\Printers\Drivers\HP Drivers") FileCopy("C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs", "C:\Printers\Scripts") FileCopy("C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs", "C:\Printers\Scripts") EndFunc ;==>CreatePrinterFolder Func BeginInstall($ServerName, $PrinterName, $PrinterModel) ; Function to create the needed variables, create a registry key for the port, restart the print spooler so the registry key (port) is available to prnmngr.vbs, and delete the printer if it already exists $PrinterPath = ("\\" & $ServerName & "\" & $PrinterName) MsgBox($MB_SYSTEMMODAL, "Boom", $PrinterPath) ; Stops print spooler, adds the necessary registry key for the port, and starts the print spooler again _RunDos("NET stop spooler") RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Ports", $PrinterPath, "REG_SZ", "") _RunDos("NET START spooler") ;Deletes the printer if it already exists. RunWait(@ComSpec & ' /c cscript "' & $PrintManagerPath & '" -d -p "' & $PrinterName & '"') If $PrinterModel = "x" Then XeroxInstall() Else HPInstall() EndIf EndFunc ;==>BeginInstall Func XeroxInstall() ;Installs the XEROX driver, first getting the printer model and .inf file, then -h for the path to the .dll Local $XeroxDriverVersion = "Xerox GPD PCL6 V3.5.404.8.0" Local $XeroxDriverPath = "C:\Printers\Drivers\Xerox Drivers\x2UNIVX.inf" ;This line runs the prndrvr.vbs script and installs the requested print driver on the machine. RunWait(@ComSpec & ' /c cscript "' & $DriverScriptPath & '" -a -m "' & $XeroxDriverVersion & '" -i "' & $XeroxDriverPath & '" -h "C:\Printers\Drivers\Xerox Drivers"') ;This line runs the prnmngr.vbs script and attaches the printer path (port) to the driver and names the resultant printer. RunWait(@ComSpec & ' /c cscript "' & $PrintManagerPath & '" -a -p "' & $PrinterName & '" -m "' & $XeroxDriverVersion & '" -r "' & $PrinterPath & '"') Finish() EndFunc ;==>XeroxInstall Func HPInstall() ;Installs the HP driver, first getting the printer model and .inf file, then -h for the path to the .dll Local $HPDriverVersion = "HP Universal Printing PCL 6 (v6.0.0)" Local $HPDriverPath = "C:\Printers\Drivers\HP Drivers\hpcu175u.inf" ;This line runs the prndrvr.vbs script and installs the requested print driver on the machine. RunWait(@ComSpec & ' /c cscript "' & $DriverScriptPath & '" -a -m "' & $HPDriverVersion & '" -i "' & $HPDriverPath & '" -h "C:\Printers\Drivers\Xerox Drivers"') ;This line runs the prnmngr.vbs script and attaches the printer path (port) to the driver and names the resultant printer. RunWait(@ComSpec & ' /c cscript "' & $PrintManagerPath & '" -a -p "' & $PrinterName & '" -m "' & $HPDriverVersion & '" -r "' & $PrinterPath & '"') Finish() EndFunc ;==>HPInstall Func Finish() _RunDos('RUNDLL32 PRINTUI.DLL,PrintUIEntry /n"' & $PrinterName & '" /k') If MsgBox(4, "Finished", "The printer has been installed and a test page has been sent to the printer." & @CRLF & " Do you want to install another?") = 7 Then Exit EndFunc ;==>Finish Edited June 3, 2016 by Trong Regards, Link to comment Share on other sites More sharing options...
AutoBert Posted June 3, 2016 Share Posted June 3, 2016 @Trong: In same loop as GuiGetMsg a sleep isn't needed. Link to comment Share on other sites More sharing options...
Trong Posted June 3, 2016 Share Posted June 3, 2016 19 minutes ago, AutoBert said: @Trong: In same loop as GuiGetMsg a sleep isn't needed. That was my bad habits, I will leave it Regards, Link to comment Share on other sites More sharing options...
lfernandes Posted June 6, 2016 Author Share Posted June 6, 2016 This works! Sorry for the super late delay, but thank you very much for all of your help! I really appreciate everything! Link to comment Share on other sites More sharing options...
lfernandes Posted June 6, 2016 Author Share Posted June 6, 2016 One other question if I may - is it possible to hide the cmd boxes that pop up throughout the install? I've tried adding the @SW Hide option at the end and it works, but then the install doesn't work. That is, it goes through the whole process as if everything worked, and then at the end it didn't actually do the install. I'm guessing this is related to the way the program types data into the cmd window. Is there a way to do that, to hide the cmd box during the install and still actually work? Link to comment Share on other sites More sharing options...
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