Sign in to follow this  
Followers 0
dumbledor

Problem running script on scheduled task

21 posts in this topic

Hello.

I prepared a script to work on my computer every night and i tried to run it with scheduled task in windows Vista. It runs and scheduled task manager gives me positive feedback. But script doesn't work. ;)

It runs every msgbox but doesn't want to open file. If i run it myself it works, but if scheduled task runs it doesn't open file.

MsgBox(0, "", "Pred odpiranjem filetka")
$log = FileOpen("C:\log.txt", 10)

MsgBox(0, "", "Za odpiranjem pred pisanjem")
FileWriteLine ($log, "****************************"&@YEAR&"-"&@MON&"-"&@MDAY&" ob "&@HOUR&":"&@MIN&":"&@SEC&"******************************************")
MsgBox(0, "", "Po pisanju")
Filewriteline ($log, "")
MsgBox(0, "", "Pred pisanjem")
FileClose($log)
MsgBox(0, "", "Za zapiranjem")

Any help? Any ideas?

Thanks in advanced.

Dumbledor

Share this post


Link to post
Share on other sites



you r opening the file to create if it doesnt exist and then erase what was in it everytime you write to it. since your last line is "", the file will be filed with nothing. you probably want mode 9 which will append to the end of the file and not write over anything.

Share this post


Link to post
Share on other sites

you r opening the file to create if it doesnt exist and then erase what was in it everytime you write to it. since your last line is "", the file will be filed with nothing. you probably want mode 9 which will append to the end of the file and not write over anything.

That is not the problem i know what 10 means. Script doesn't create file or change it when i run script in schudled task.

Share this post


Link to post
Share on other sites

You can't use msgbox in a scheduled task. You'll never see it, and there's no timeout on them so the task is probably running with a hidden msgbox on your system. Take out anything that requires someone to click off the message boxes.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I used MsgBox just for checking if script works. And funny thing is that i get msg from box and i can read it and click it, but file is not opened and saved.

Any ideas?

Share this post


Link to post
Share on other sites

What credentials is the task running under? Try writing to a less protected area than the root of the C: drive, especially in Vista/7. Put in some error checking to see what is happening and where it's failing. Get rid of the message boxes for the scheduled task. That's all I can think of right now off the top of my head. You need to find out why it's failing, and then correct the problem.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I will try, what you suggested. I was abroad for one week. I will report the results. Thank you for helping.

Dumbledor

Share this post


Link to post
Share on other sites

Ok. I prepared example.

This code creates log.txt file reads from tester.txt and then creates file test-exe.txt.

It runs great if i run it. If i run schudled task in Vista the task is running and nothing happens.

Any ideas?

Dumbledor

Attachment:

tester.au3

tester.exe

tester.txt

tester.ini

forum.zip

Share this post


Link to post
Share on other sites

I can't open the zip file, says it's not a valid zip format.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I already read that and i didn't use any of functions there. I researched forum and didn't find answer.

My code:

#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.8.1
Author:      myName
Script Function:
Template AutoIt script.
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <File.au3>
#include <Array.au3>

;Do
;if (@HOUR = 20) Then
$log = FileOpen("log.txt", 9)
FileWriteLine ($log, "****************************"&@YEAR&"-"&@MON&"-"&@MDAY&" ob "&@HOUR&":"&@MIN&":"&@SEC&"******************************************")
Filewriteline ($log, "")
;prebere vrednosti iz ini
$branje_pot = IniRead("tester.ini", "section", "branje_pot", "NotFound")
If $branje_pot = "NotFound" Then
    FileWriteLine($log, $branje_pot)
    Exit
EndIf

$pisanje_datoteke = IniRead("tester.ini", "section", "pisanje_datoteke", "NotFound")
If $pisanje_datoteke = "NotFound" Then
    FileWriteLine($log,"Error reading ini file 4/4.")
    Exit
EndIf
FileWriteLine($log, "Reading ini - OK")
$file = FileOpen($branje_pot, 0)
$file2 = FileOpen($pisanje_datoteke, 10)
If $file = -1 Then
   
FileWriteLine($log,"No Files Found1.")
    Exit
EndIf
If $file2 = -1 Then
   
FileWriteLine($log,"No Files Found2.")
    Exit
EndIf

FileWriteLine($file2, "test")
FileWriteLine($file2, "")
Local $line = FileReadLine($file, 2)
FileWriteLine($file2, $line)

FileClose($file2)
FileClose($file)
FileWriteLine($log,"Zaprti datumi.")
FileClose($log)

My tester.ini file:

[section]
branje_pot=tester.txt
pisanje_datoteke=test-exe.txt

Share this post


Link to post
Share on other sites

If you look you'll see I had what I believe is a similar issue. It was solved with the help of BrewManNH by placing the script in a folder on the root drive ©. I believe the issue was somehow a permission thing.

My apologies if I misunderstood your question.

Share this post


Link to post
Share on other sites

Thanks for answering, but i already tried that and it doesn't work. I read your article.

Share this post


Link to post
Share on other sites

One suggestion I can think of is to not use relative paths to the files. Use the full path name and file name instead. It's quite possible that the task can't find the files where it thinks they are.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Already tried that. Anbody got any idea, i have a lot of procedures written in Delphi, i like autoit more, so i would be delighted if this could work.

Thanks for trying to help me i appriciated.

Share this post


Link to post
Share on other sites

; From: tester.ini

; [section]
; branje_pot=tester.txt
; pisanje_datoteke=test-exe.txt

; 1) Does the file exist?
; 2) Where? In the same folder as your script or another folder?

If Not FileExists($branje_pot) Then
    MsgBox(0, '', 'File Not Found!')
    Exit
EndIf

; Maybe works better with Full Path...

; [section]
; branje_pot=C:MyTestFoldertester.txt
; pisanje_datoteke=C:MyTestFolderAnotherFoldertest-exe.txt


Make yourself sheep and the wolves will eat you - Benjamin Franklin

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

; From: tester.ini

; [section]
; branje_pot=tester.txt
; pisanje_datoteke=test-exe.txt

; 1) Does the file exist?
; 2) Where? In the same folder as your script or another folder?

If Not FileExists($branje_pot) Then
MsgBox(0, '', 'File Not Found!')
Exit
EndIf

; Maybe works better with Full Path...

; [section]
; branje_pot=C:MyTestFoldertester.txt
; pisanje_datoteke=C:MyTestFolderAnotherFoldertest-exe.txt

1. Yes it exists

2. No. In network drive.

Tried full path that doesn't make a difference. :(

Any ideas?

Edited by dumbledor

Share this post


Link to post
Share on other sites

I prepared a script to work on my computer every night and i tried to run it with scheduled task in windows Vista. It runs and scheduled task manager gives me positive feedback. But script doesn't work.

I've got the same issue with Vista x64, user having administrative privileges, also tested with UAC on/off.

I've never had any luck with running any scheduled compiled script, even the simplest one like "open a file - write a line - close the file". Played about 2 days with it and finally gave up - Vista always says that the task has begun but it's a lie actually.

I've just looped my script to run endlessly and check for some particular time to update. It takes only a couple of lines of code.

Anyway I'll be glad to have a solution with windows scheduler too :)

Share this post


Link to post
Share on other sites

I finally found the stupid solution. :) it took me 2 years. :) I did other things too. ;)

OK here it goes.

post-30220-0-79384200-1406884767_thumb.p

All you have to do is put the path to program in Start in (optional).

I also did this, maybe is need:

You should grant to the specified user access to COM automation factory:

  • 1) Start->Run->dcomcnfg
  • 2) Component Services->Computers->My Computer
  • 3) Right-click My Computer, Properties
  • 4) COM Security tab, Launch and Activation Permissions, Edit Default
  • 5) Add all access rights for the specified user, you are using to run scheduled task.

Hope it helps. Please replay if it is working for you. :)

1 person likes this

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

  • Similar Content

    • nss
      By nss
      Hi all.
       
      Because of me wondering if I could access the key/value pair arrays with the numbers as indexes, I have found out that the zeroth element for some reason doesn't return anything.
      Here's the example:
       
      local $r[2] $r["test1"]="hello" $r["test2"]="how are you" msgbox(64, $r[0], $r[1]) ; prints the ["test2"] but not ["test1"]. Is this even supposed to be a thing?  
       
      BTW, I haven't seen Autoit get updated since 2015; is it abandened or something?
      Any help/clarification appreciated.
    • 4evrplan
      By 4evrplan
      First the Situation:
      I'm trying to automate an image uploading utility which lives on the client side of some cloud based server/client software and which was not designed to be automated. I've got a 2012 R2 VM running with autologon enabled on a local account.  The account with autologon enabled has a scheduled task set up to run at 4AM daily.  This task merely runs my AutoIt script.
      Now the issue:
      If I remote into my VM and run the script manually, it runs perfectly. If I edit my scheduled task to run only a few minutes in the future, and then reboot the VM, it also works perfectly. If I leave it to run overnight, the script starts but never finishes. It seems to be getting hung up waiting for the first window to become active. I've tried many version of the script now with no luck.  The latest version is below.
      #include <File.au3> Dim $un = "username" Dim $pw = "password" ; Login window Run("C:\Program Files (x86)\CSI Software\Spectrum NG\Spectrum NG Client\SNGImageUploader.exe") Dim $hLogin = WinWait("[CLASS:WindowsForms10.Window.8.app.0.2bf8098_r11_ad1]", "Version: ") SendKeepActive($hLogin) WinActivate($hLogin) Send($un & "{TAB}" & $pw & "{ENTER}") SendKeepActive("") ; Main window - 1/3 Dim $hMain = WinWaitActive("SNG Image Uploader") SendKeepActive($hMain) Send("{TAB}{ENTER}") SendKeepActive("") ; File browser window Dim $hBrowse = WinWaitActive("Browse For Folder") SendKeepActive($hBrowse) Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{DOWN}") Sleep(2000) ; Give the program moment to detect images in the directory Send("{ENTER}") SendKeepActive("") ; Main window - 2/3 SendKeepActive($hMain) WinWaitActive($hMain) Send("{TAB}{ENTER}") SendKeepActive("") ; Upload complete window Dim $hUpload = WinWaitActive("[CLASS:#32770]", "Upload complete. Please wait while servers process your request.") SendKeepActive($hUpload) Send("{ENTER}") SendKeepActive("") ; Import complete window Dim $hImport = WinWaitActive("[CLASS:#32770]", "Image import completed. Please check results in the Account Upload History screen.") SendKeepActive($hImport) Send("{ENTER}") SendKeepActive("") ; Main window - 3/3 WinWaitActive($hMain) WinClose($hMain) ; Cleanup FileDelete("C:\CRPics\*")  
    • ManneMoses
      By ManneMoses
      Hey there,
      Probably you know about the many questions on this forum, how to disable Ctrl-Alt-Del. I searched the whole forum bot there was not only one answer that worked. But now i found a way on my own hot to prevent that. And btw I have to say that this if f*cking easy, so shame on you  You can try it, it works sure on windows 7 and vista. I also included a hotkey function to exit, but it takes up to 10 seconds until you can access the ctrl alt del screen again. Please tell me if you found out a better way and tell me what is your meaning about my script. Thank you
      -snip-
      Edit: This is the hard way, and i just wanted to show how it could be done. I am confused, no one before me mentioned this script
    • ludocus
      By ludocus
      Dear all,
      I'm creating this program where the goal is to automate some mouse -click and dragging on an external application.
      Now the problem is, this external application is blocking every automate mouse moves, clicks or anything related to using the mouse.
      So I figured autoit uses postmessage and user32.dll to move the mouse and that this application blocks these attempts.
      Now I'm wondering if there's a different way to move the mouse so it'll go undetected by this external app.
      Any other suggestions are welcome to.
      Thnx in advance
    • Shanheavel
      By Shanheavel
      I've noticed a strange phenomenon, namely the script loops indefinitely when I use "Array" word in the string.
      Try this:
      #include <Array.au3> Global $aStrings = StringSplit("Apple,Orange,Array,Milk", ",") _ArrayDisplay($aStrings) For $array = 1 To $aStrings[0] MsgBox(32, "", $aStrings[$array]) Assign($aStrings[$array], $aStrings[$array], 2) Next It never ends, right?
      Now try another one. Just change "Array" to "Cola" for example. It should works fine.
      I'm not sure, is it a bug?