ReitzelTechnology Posted November 20, 2010 Share Posted November 20, 2010 We would like to run a script when a user logs in to automatically connect to a network printer, and then pause (icon stays in notificication area) and in like 30 minutes reexecute the script (kinda on a loop). IE: Like how when you run a script, the AutoIt icon is the taskbar, we want it to be there all the time and just reexecute the script every so often. Link to comment Share on other sites More sharing options...
JohnOne Posted November 20, 2010 Share Posted November 20, 2010 While 1 _MyScript($Params) Sleep(1000*60*30) WEnd Func _MyScript($args) ;code EndFunc AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ReitzelTechnology Posted November 20, 2010 Author Share Posted November 20, 2010 While 1 _MyScript($Params) Sleep(1000*60*30) WEnd Func _MyScript($args) ;code EndFunc We figured out how to get it to work, but when it stays in the taskbar, we want to be able to right click it and force it to rerun the script, or click the exit button. Link to comment Share on other sites More sharing options...
SadBunny Posted November 20, 2010 Share Posted November 20, 2010 The helpfile is your friend. Try the example script for the TrayCreateMenu - it seems to be exactly what you are looking for. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
ReitzelTechnology Posted November 20, 2010 Author Share Posted November 20, 2010 The helpfile is your friend. Try the example script for the TrayCreateMenu - it seems to be exactly what you are looking for. We got the menu to come up right, but now the actual script doesn't execute. Our script before the menu change started at where is says $I0 and it worked. expandcollapse popupOpt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. TrayCreateItem("") $refreshitem = TrayCreateItem("Refresh") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $refreshitem ShellExecute(@ScriptFullPath) ExitLoop Case $msg = $exititem ExitLoop EndSelect WEnd Exit $I0 = @ComSpec & " /c " & 'cscript.exe "\\rtssrv\netlogon\SET_Default_Printer.vbs"' useprinter("\\RTSSRV\CMF4370DN") usefaxprinter("\\RTSSRV\CMF4370DN_FX") func useprinter($uncpath) $serverAr = stringsplit($uncpath,"\") $server = $serverAr[3] if (ping($server)) then run(@comspec &' /c Rundll32 printui.dll,PrintUIEntry /in /n "' & $uncpath &'"',"",@SW_HIDE) endif endfunc func usefaxprinter($uncpath) $serverAr = stringsplit($uncpath,"\") $server = $serverAr[3] if (ping($server)) then run(@comspec &' /c Rundll32 printui.dll,PrintUIEntry /in /n "' & $uncpath &'"',"",@SW_HIDE) endif endfunc RunWait($I0,"","",@SW_HIDE) Sleep(18000000) ShellExecute(@ScriptFullPath) Link to comment Share on other sites More sharing options...
JohnOne Posted November 20, 2010 Share Posted November 20, 2010 Dont you need TrayCreateMenu() first befor you go creating Items? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ReitzelTechnology Posted November 20, 2010 Author Share Posted November 20, 2010 Dont you need TrayCreateMenu() first befor you go creating Items?I don't know. I just need to know what I need to change to make it work. I don't understand how to make it work. Link to comment Share on other sites More sharing options...
SadBunny Posted November 20, 2010 Share Posted November 20, 2010 (edited) Seems like you need to at least remove the ExitLoop from your refreshitem code. Since the exitloop exits the main while loop, and there is an Exit right below it, the loop will be exited not only if you press the Exit option but also if you press the Refresh button. By the way I tried replacing your exitloop code with a simple messagebox and that seems to work fine, even without the TrayCreateMenu that JohnOne suggested. Only the options in the menu have checkboxes, you might want to delve into the helpfile a bit deeper if you deem it important enough to change that. Edited November 20, 2010 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
ReitzelTechnology Posted November 20, 2010 Author Share Posted November 20, 2010 Seems like you need to at least remove the ExitLoop from your refreshitem code. Since the exitloop exits the main while loop, and there is an Exit right below it, the loop will be exited not only if you press the Exit option but also if you press the Refresh button.The exitloop is there because when you click refresh, I want it to restart the script from the start. The menu stuff works fine, but insted of it executing the script to map the printers, it just sits there. Link to comment Share on other sites More sharing options...
ReitzelTechnology Posted November 20, 2010 Author Share Posted November 20, 2010 I want it to have the following menu when you right click on it: "Refresh Printers" "Exit PrintMgr" The exit would quit out of the script and the Refresh should rerun the functions at the bottom to remap the printers. I'm not sure how to code it. Link to comment Share on other sites More sharing options...
JohnOne Posted November 20, 2010 Share Posted November 20, 2010 Try this expandcollapse popupOpt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. TrayCreateItem("") $refreshitem = TrayCreateItem("Refresh") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $refreshitem _Run() Case $msg = $exititem ExitLoop EndSelect WEnd Exit Func useprinter($uncpath) $serverAr = StringSplit($uncpath, "\") $server = $serverAr[3] If (Ping($server)) Then Run(@ComSpec & ' /c Rundll32 printui.dll,PrintUIEntry /in /n "' & $uncpath & '"', "", @SW_HIDE) EndIf EndFunc ;==>useprinter Func usefaxprinter($uncpath) $serverAr = StringSplit($uncpath, "\") $server = $serverAr[3] If (Ping($server)) Then Run(@ComSpec & ' /c Rundll32 printui.dll,PrintUIEntry /in /n "' & $uncpath & '"', "", @SW_HIDE) EndIf EndFunc ;==>usefaxprinter Func _Run() $I0 = @ComSpec & " /c " & 'cscript.exe "\\rtssrv\netlogon\SET_Default_Printer.vbs"' useprinter("\\RTSSRV\CMF4370DN") usefaxprinter("\\RTSSRV\CMF4370DN_FX") RunWait($I0, "", "", @SW_HIDE) Sleep(18000000) ShellExecute(@ScriptFullPath) EndFunc ;==>_Run AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
SadBunny Posted November 20, 2010 Share Posted November 20, 2010 (edited) The exitloop is there because when you click refresh, I want it to restart the script from the start. The menu stuff works fine, but insted of it executing the script to map the printers, it just sits there.Well in any case, at it is now the exitloop exits the main while loop and then the interpreter encounters an Exit and exits the script. That doesn't make it restart itself, it just makes it, well, exit the script.... sorry for my perhaps somewhat sarcastic remark above, didn't mean to be mean... JohnOne was more helpful. Good luck with his solution! Edited November 20, 2010 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
JohnOne Posted November 20, 2010 Share Posted November 20, 2010 I'm unsure why the ShellExecute(@ScriptFullPath) is in there though, wont that just start another instance of your script? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ReitzelTechnology Posted November 20, 2010 Author Share Posted November 20, 2010 Try this expandcollapse popupOpt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. TrayCreateItem("") $refreshitem = TrayCreateItem("Refresh") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $refreshitem _Run() Case $msg = $exititem ExitLoop EndSelect WEnd Exit Func useprinter($uncpath) $serverAr = StringSplit($uncpath, "\") $server = $serverAr[3] If (Ping($server)) Then Run(@ComSpec & ' /c Rundll32 printui.dll,PrintUIEntry /in /n "' & $uncpath & '"', "", @SW_HIDE) EndIf EndFunc ;==>useprinter Func usefaxprinter($uncpath) $serverAr = StringSplit($uncpath, "\") $server = $serverAr[3] If (Ping($server)) Then Run(@ComSpec & ' /c Rundll32 printui.dll,PrintUIEntry /in /n "' & $uncpath & '"', "", @SW_HIDE) EndIf EndFunc ;==>usefaxprinter Func _Run() $I0 = @ComSpec & " /c " & 'cscript.exe "\\rtssrv\netlogon\SET_Default_Printer.vbs"' useprinter("\\RTSSRV\CMF4370DN") usefaxprinter("\\RTSSRV\CMF4370DN_FX") RunWait($I0, "", "", @SW_HIDE) Sleep(18000000) ShellExecute(@ScriptFullPath) EndFunc ;==>_Run This script worked, but I had to click the Refresh button to make to go. How do you make it when it runs, it does the same as when you click the refresh button? Link to comment Share on other sites More sharing options...
JohnOne Posted November 20, 2010 Share Posted November 20, 2010 Just add _Run() underneath TraySetState() AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ReitzelTechnology Posted November 20, 2010 Author Share Posted November 20, 2010 (edited) Just add _Run() underneath TraySetState()I got everything to run as I want it, but when you click the menu commands, nothing happens. Edited November 20, 2010 by ReitzelTechnology Link to comment Share on other sites More sharing options...
JohnOne Posted November 20, 2010 Share Posted November 20, 2010 (edited) Probably because its sleeping expandcollapse popupOpt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. AdlibRegister("_Run",1000*60*30) TrayCreateItem("") $refreshitem = TrayCreateItem("Refresh") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() _Run() While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $refreshitem _Run() Case $msg = $exititem ExitLoop EndSelect WEnd Exit Func useprinter($uncpath) $serverAr = StringSplit($uncpath, "\") $server = $serverAr[3] If (Ping($server)) Then Run(@ComSpec & ' /c Rundll32 printui.dll,PrintUIEntry /in /n "' & $uncpath & '"', "", @SW_HIDE) EndIf EndFunc ;==>useprinter Func usefaxprinter($uncpath) $serverAr = StringSplit($uncpath, "\") $server = $serverAr[3] If (Ping($server)) Then Run(@ComSpec & ' /c Rundll32 printui.dll,PrintUIEntry /in /n "' & $uncpath & '"', "", @SW_HIDE) EndIf EndFunc ;==>usefaxprinter Func _Run() $I0 = @ComSpec & " /c " & 'cscript.exe "\\rtssrv\netlogon\SET_Default_Printer.vbs"' useprinter("\\RTSSRV\CMF4370DN") usefaxprinter("\\RTSSRV\CMF4370DN_FX") RunWait($I0, "", "", @SW_HIDE) EndFunc ;==>_Run Notice the Adlbregister funcrtion at the top, that will run it every 30 minutes Edited November 20, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ReitzelTechnology Posted November 20, 2010 Author Share Posted November 20, 2010 Probably because its sleeping expandcollapse popupOpt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. AdlibRegister("_Run",1000*60*30) TrayCreateItem("") $refreshitem = TrayCreateItem("Refresh") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() _Run() While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $refreshitem _Run() Case $msg = $exititem ExitLoop EndSelect WEnd Exit Func useprinter($uncpath) $serverAr = StringSplit($uncpath, "\") $server = $serverAr[3] If (Ping($server)) Then Run(@ComSpec & ' /c Rundll32 printui.dll,PrintUIEntry /in /n "' & $uncpath & '"', "", @SW_HIDE) EndIf EndFunc ;==>useprinter Func usefaxprinter($uncpath) $serverAr = StringSplit($uncpath, "\") $server = $serverAr[3] If (Ping($server)) Then Run(@ComSpec & ' /c Rundll32 printui.dll,PrintUIEntry /in /n "' & $uncpath & '"', "", @SW_HIDE) EndIf EndFunc ;==>usefaxprinter Func _Run() $I0 = @ComSpec & " /c " & 'cscript.exe "\\rtssrv\netlogon\SET_Default_Printer.vbs"' useprinter("\\RTSSRV\CMF4370DN") usefaxprinter("\\RTSSRV\CMF4370DN_FX") RunWait($I0, "", "", @SW_HIDE) EndFunc ;==>_Run Notice the Adlbregister funcrtion at the top, that will run it every 30 minutes Thanks! That got it to 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