Jump to content

Problem running script on scheduled task


Go to solution Solved by dumbledor,

Recommended Posts

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

Link to comment
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.

Link to comment
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.

Link to comment
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

Link to comment
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

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

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

Link to comment
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

Link to comment
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
Link to comment
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

Link to comment
Share on other sites

  • 2 months later...

; 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

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

  • 2 months later...

; 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
Link to comment
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 :)

Link to comment
Share on other sites

  • 1 year later...
  • Solution

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. :)

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...