Jump to content

Run Script all the time


Recommended Posts

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

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.

Opt("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

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 by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

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

Try this

Opt("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

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! :graduated:

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Try this

Opt("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

Probably because its sleeping

Opt("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 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

Probably because its sleeping

Opt("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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...