Sign in to follow this  
Followers 0
daashag

Running script as scheduled task.

15 posts in this topic

Is there a way to run a script that manipulates windows as a schedule task. Everything I have tried so far just opens the program when ran as a scheduled task. I have tried to run it as service, ControlClick(), ControlSend(), and regualar window controls. Any help would be appreciated. Thanks

Share this post


Link to post
Share on other sites



Hi,

if that all shouldn't work, then you could use a script to lock the pc by yourself and then run the script.

But back to your points: where is your prob? Which error message?

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Thanks for your reply

But back to your points: where is your prob? Which error message?

No error message as far as I can tell. It just won't do sends. Its hard to tell when its botching since its running in the background and all I can see is the process in task manager.

if that all shouldn't work, then you could use a script to lock the pc by yourself and then run the script.

Not sure what you mean by that. I thought about running a script that logins to the another machine and then maybe it will get a desktop. All this is hard to verify because as far as I can tell a scheduled task runs in the background. Anyway here is the first part of my script.
;Script to Automate Exact backup

#include "ServiceControl.au3"
$servicename = "ExactBackup"
_CreateService("", $servicename, "My AutoIt Script", "C:\Programfiles\srvany\srvany.exe", "LocalSystem", "", 0x110)
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\" & $servicename & "\Parameters", "Application", "REG_SZ", @ScriptFullPath)

;Declare Variables
$cpdst = 'x:\ExactGlobe\ftpbackup\'
;MsgBox(0, "Example", "My variable is " & $bkupsrc)

;Delete files in current directory
FileDelete($cpdst)

Opt("WinDetectHiddenText", 1)

;Run Exact
Run('"' & @ProgramFilesDir & '\Exact Software\bin\e4shell.exe"')

<-------------------  This is where I think it's stalling.

sleep(500)
; Cancel opening company
WinWait("Open company", "TROON")
;$var = ControlGetText("Open company", "&Cancel", "&Cancel")
ControlSend("Open company", "&Cancel", "&Cancel", "!c")
;MsgBox(0, "Example", "My variable is " & $var)

sleep(500)
; Enter Menu
WinWait("Exact Globe 2003 Enterprise", "Progress Bar")
ControlSend("Exact Globe 2003 Enterprise", "", "", "!f")

sleep(500)
;Enter backup screen
WinWaitActive("Exact Globe 2003 Enterprise")
ControlSend("Exact Globe 2003 Enterprise", "", "", "k")oÝ÷ Øèºwm+¡×ÉaÄ,ËajÛ¬zɬ¶Ç-¢Z x§¶£7öhî²ÙèÂË«z0¶è­²'qè­"È­ºÇ¬¶«zj-y׬Ú){-y§h~Ø^Ê&¦ë^®Ú)z·è®l"Ú0rí®ljëh×6$servername = "server"
$username = "user"
$password = "password"
run("mstsc /console /v:"& $servername)
WinWaitClose("Connecting")
Opt("WinTitleMatchMode", 4)
WinWaitActive("classname=TSSHELLWND")
Sleep(2000)
Send("!u")
Send($username)
Sleep(500)
Send("!p")
Send($password)
Send("{ENTER}")
Opt("WinTitleMatchMode", Default)

Thanks again

Share this post


Link to post
Share on other sites

Hi,

i meat this by using winlock.dll:

#include <GuiConstants.au3>
#include <File.au3>
#include <misc.au3>
#notrayicon
$version = "2.0"
Opt("WinTitleMatchMode", 4)
Global $blockingKey = "111"
Global $codeGiven = False, $inputCode, $splash = 0

code()

HotKeySet("!{TAB}", "doNothing")
HotKeySet("{TAB}", "doNothing")
HotKeySet("{ESC}", "doNothing")
HotKeySet("{F9}", "code")
HotKeySet("!^{F9}", "OnAutoItExit") ; STRG+ALT+F9 Sofort-Exit

$safeGUI = GUICreate('')
GUISetState($WS_EX_TRANSPARENT, $safeGUI)
$blockGUI = GUICreate(" *Mega*", @DesktopWidth, @DesktopHeight, -1, -1, -1, -1, $safeGUI)
GUISetState()

WinMinimizeAll()
WinSetTrans(" *Mega*", "", 1)
$dll = DllOpen("user32.dll")
WinSetOnTop(" *Mega*", "", 1)

; The scriptyou want to run
$startPath = "c:\Downloads\AutoIt-Skripte\Entwicklung\ForumTests\MegaBlock\NotePadTut.exe"

While 1
    For $i = 1 To 91
        If _IsPressed($i, $dll) Or _IsPressed("0D", $dll) Then
            doNothing()
        EndIf
        ToolTip("Protected by,     *Mega*   v" & $version & " | " & @HOUR & ":" & @MIN & ":" & @SEC, 5, 5)
    Next
    _MouseTrap(95, 18, 140, 22)
    WinSetOnTop(" *Mega*", "", 1)
    Sleep(1) ; save CPU
WEnd

Func code()
    $inputCode = InputBox(" *Mega*", "The code please: ", "", "*10", 150, 120, 50, 50, 10)
    
    If $codeGiven = False Then
        If $inputCode = $blockingKey Then
            secure()
            $codeGiven = True
            Return
        Else
            MsgBox(64, " *Mega*", "Wrong code for blocking!", 3)
            Exit
        EndIf
    Else
        If $inputCode = $blockingKey Then
            DllClose($dll)
            SplashOff()
            MsgBox(64, "Info - Administrator", "This PC has been unlocked!" & @LF & @LF & _
                    "Tel.: XXXX" & @LF & _
                    "Email: Mega@xxx.com" & @LF & _
                    @LF & _
                    "Mega", 3)
            _MouseTrap()
            Sleep(2000)
            Exit
        Else
            WinSetOnTop(" *Mega*", "", 1)
            Return
        EndIf
    EndIf
EndFunc   ;==>code


Func secure()
    WinMinimizeAll()
    ;Hide Taskbar
    DllCall("WinLockDll.dll", "Int", "Taskbar_Show_Hide", "Int", "0")
    ;Disable CrtlAltDel
    $splash = SplashTextOn("", "Administrator : This PC is locked!" & @LF & @LF & _
            "Tel.: XXXX" & @LF & @LF & _
            "Email: Mega@xxx.com" & @LF & _
            @LF & @LF & _
            "Mega", _
            550, @DesktopHeight / 2, 1, 500, 1, 5, 16, 600)
    DllCall("WinLockDll.dll", "Int", "CtrlAltDel_Enable_Disable", "Int", "0")
    DllCall("WinLockDll.dll", "Int", "Desktop_Show_Hide", "Int", "0")
EndFunc   ;==>secure

;DllCall("WinLockDll.dll", "Int", "Process_Desktop", "str", "MyDesktop2", "str", "cmd.exe")

Func OnAutoItExit()
    WinMinimizeAllUndo()
    _MouseTrap()
    DllCall("WinLockDll.dll", "Int", "Desktop_Show_Hide", "Int", "1")
    DllCall("WinLockDll.dll", "Int", "CtrlAltDel_Enable_Disable", "Int", "1")
    DllCall("WinLockDll.dll", "Int", "Taskbar_Show_Hide", "Int", "1")
    SplashOff()
    Exit (0)
EndFunc   ;==>OnAutoItExit

Func doNothing()
    _MouseTrap(95, 18, 140, 22)
    WinSetState("Windows Task-Manager", "", @SW_HIDE)
    WinSetOnTop(" *Mega*", "", 1)
EndFunc   ;==>doNothing

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

I'm still not following you on this one. I don't understand why locking the PC will let you run a script as a scheduled task. I haven't really been able to test it because my server is in a remote location and I don't want to lock it. I tried your code on my computer and it locks it but then there is no way to unlock it, at least that I could tell. I probably need a script with a hotkey to unlock the PC and also it would have to lock the PC run my script then unlock it. But then again I still don't get why locking the PC would solve my particular problem. Thanks

Share this post


Link to post
Share on other sites

I'm still not following you on this one. I don't understand why locking the PC will let you run a script as a scheduled task. I haven't really been able to test it because my server is in a remote location and I don't want to lock it. I tried your code on my computer and it locks it but then there is no way to unlock it, at least that I could tell. I probably need a script with a hotkey to unlock the PC and also it would have to lock the PC run my script then unlock it. But then again I still don't get why locking the PC would solve my particular problem. Thanks

HI,

you do not have to. Some time ago in another forum somebody told me, that his script uses Send and the on which wouldn't work if the system is locked. So I made a script for him, which locks the pc and let his script run too.

To explain, you need this

HotKeySet("{F9}", "code") to type the code to exit the lock (press F9 and then 111)

HotKeySet("!^{F9}", "OnAutoItExit") ; CTRL+ALT+F9 to exit adhoc.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Either it doesn't work or I am doing something wrong. I modified your script so it doesn't require a code to lock the PC, then I set up both your script and and a winzip install script to run as a scheduled task. Of course your script runs first to lock the PC. I then logged out and waited for the tasks to run. When I log back in both scripts are running according to the processor table, the PC is locked, and the winzip install script is stalled at the first setup window.

Here are the two modified scripts.

lock PC

#include <GuiConstants.au3>
#include <File.au3>
#include <misc.au3>
#notrayicon
$version = "2.0"
Opt("WinTitleMatchMode", 4)
Global $blockingKey = "111"
;Global $codeGiven = False, $inputCode
Global $splash = 0


HotKeySet("!{TAB}", "doNothing")
HotKeySet("{TAB}", "doNothing")
HotKeySet("{ESC}", "doNothing")
;HotKeySet("{F9}", "code")
HotKeySet("{F9}", "OnAutoItExit") ; STRG+ALT+F9 Sofort-Exit

$safeGUI = GUICreate('')
GUISetState($WS_EX_TRANSPARENT, $safeGUI)
$blockGUI = GUICreate(" *Mega*", @DesktopWidth, @DesktopHeight, -1, -1, -1, -1, $safeGUI)
GUISetState()

WinMinimizeAll()
WinSetTrans(" *Mega*", "", 1)
$dll = DllOpen("user32.dll")
WinSetOnTop(" *Mega*", "", 1)

; The scriptyou want to run
$startPath = "c:\Downloads\AutoIt-Skripte\Entwicklung\ForumTests\MegaBlock\NotePadTut.exe"

While 1
    For $i = 1 To 91
        If _IsPressed($i, $dll) Or _IsPressed("0D", $dll) Then
            doNothing()
        EndIf
        ToolTip("Protected by,     *Mega*   v" & $version & " | " & @HOUR & ":" & @MIN & ":" & @SEC, 5, 5)
    Next
    _MouseTrap(95, 18, 140, 22)
    WinSetOnTop(" *Mega*", "", 1)
    Sleep(1) ; save CPU
WEnd




Func secure()
    WinMinimizeAll()
    ;Hide Taskbar
    DllCall("WinLockDll.dll", "Int", "Taskbar_Show_Hide", "Int", "0")
    ;Disable CrtlAltDel
    $splash = SplashTextOn("", "Administrator : This PC is locked!" & @LF & @LF & _
            "Tel.: XXXX" & @LF & @LF & _
            "Email: Mega@xxx.com" & @LF & _
            @LF & @LF & _
            "Mega", _
            550, @DesktopHeight / 2, 1, 500, 1, 5, 16, 600)
    DllCall("WinLockDll.dll", "Int", "CtrlAltDel_Enable_Disable", "Int", "0")
    DllCall("WinLockDll.dll", "Int", "Desktop_Show_Hide", "Int", "0")
EndFunc   ;==>secure

;DllCall("WinLockDll.dll", "Int", "Process_Desktop", "str", "MyDesktop2", "str", "cmd.exe")

Func OnAutoItExit()
    WinMinimizeAllUndo()
    _MouseTrap()
    DllCall("WinLockDll.dll", "Int", "Desktop_Show_Hide", "Int", "1")
    DllCall("WinLockDll.dll", "Int", "CtrlAltDel_Enable_Disable", "Int", "1")
    DllCall("WinLockDll.dll", "Int", "Taskbar_Show_Hide", "Int", "1")
    SplashOff()
    Exit (0)
EndFunc   ;==>OnAutoItExit

Func doNothing()
    _MouseTrap(95, 18, 140, 22)
    WinSetState("Windows Task-Manager", "", @SW_HIDE)
    WinSetOnTop(" *Mega*", "", 1)
EndFunc   ;==>doNothingoÝ÷ ÙÊ%¢ºM4ÒÊZËr

I want to run a script while logged out. Has anyone been able to accomplish this, or know if this is even possible. Appreciate any input if someone has experience with this.

Thanks

Share this post


Link to post
Share on other sites

The scheduled task needs to be able to "interact with the desktop" and/or be run with logged on users credentials, or the Win commands will not be priveleged to work.

Appreciate your response Lar,

But how do you do this? I already tried the RunAsSet() command to no avail. Also how do I get the task to be able to interact with the desktop? Thanks

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I want to run a script as a schedule task. The script runs fine when I initiate the script manually while logged in.

The script needs to open a program go through some selections than close the program. All it does is open the program when ran as scheduled task.

Thanks

Edited by daashag

Share this post


Link to post
Share on other sites

did you go into the advanced settings of the task and give the user credentials? Are you making sure the PC is not locked or logged off when the task runs.

Appreciate your help Lar,

Yeah I am running the task with administrator credentials. The PC in this case is a server so if remote Desktop in and just minimize the window instead of logging off it will run. But if I am logged off it won't.

Do you think if I had a script RDP in and then run the task that would work. I have got it so I can RDP in, I am just not sue how to give focus to the remote desktop for control commands.

Thanks

Share this post


Link to post
Share on other sites

Is this possible? Does anyone know how to do this? Appreciate any help on this.

Share this post


Link to post
Share on other sites

With RDP you can setup a script to run as you log into the machine with rdp. So as soon as you log in your winzip is executed and installed on the remote machine. :).

Share this post


Link to post
Share on other sites

Try using something other than the windows remote connection to log into the server try using realvnc I had a script awhile back that wouldnt run right if I used the windows remote connection just a thought

Share this post


Link to post
Share on other sites

If I may ask, what is the ultimate goal?

Share this post


Link to post
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
Sign in to follow this  
Followers 0