Sign in to follow this  
Followers 0
Qual-IT London

at

12 posts in this topic

I create a scheduled task by using the AT command

There is no way of naming the At command, they just appear in scheduled tasks as AT1 AT2 etc

What I would like to do, is be able to is name it. Obviously I cant so the answer is to rename it From c:\windows\tasks\at1.job to "myjob.job"

But..

Any idea how I can get the name of the task I just created?

Perhaps its possible to look at all the jobs and get the filename of the one created in the last minute?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You have to figure out what to name it, you could do that through an input box.

RunWait(@ComSpec & " /c " & "at 9:00AM /interactive C:\MPEG2Cut.exe"); Your Previous Code that generated the AT job
$filename = "John"; The File name wou want.
$Scheduledfiles = _FileListToArray(@WINDOWSDIR & "\Tasks", "at*.job")
If IsArray($Scheduledfiles) Then
    For $i = 1 To $Scheduledfiles[0]
        $time = FileGetTime(@WINDOWSDIR & "\Tasks\" & $Scheduledfiles[$i],1, 1)
        $now = @YEAR & @MON & @MDAY & @HOUR & @MIN
        If StringInStr(StringTrimRight($time,2),$now) Then
            FileMove(@WINDOWSDIR & "\Tasks\" & $Scheduledfiles[$i],@WINDOWSDIR & "\Tasks\" & $filename & ".job") 
        Else
            MsgBox(0,"Error","No files with the correct time code found")
            EndIf
        Next
EndIf

It won't be viewable by AT any longer.

Edited by MikelSevrel

Coming soon....

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Funny, I just replied to your previous sheduled task post with an idea for just that!

Check for QshedTask.job first and you know if you already have added the task

Do a FileFindFirstFile and FileFindNextFile to get a list of files, then create new task if it QshedTask doesn't already exist.

Get a second list of files, the different one is the new task, then rename it to QshedTask.job

Edited by ChrisL

Share this post


Link to post
Share on other sites

You have to figure out what to name it, you could do that through an input box.

RunWait(@ComSpec & " /c " & "at 9:00AM /interactive C:\MPEG2Cut.exe"); Your Previous Code that generated the AT job
$filename = "John"; The File name wou want.
$Scheduledfiles = _FileListToArray(@WINDOWSDIR & "\Tasks", "at*.job")
If IsArray($Scheduledfiles) Then
    For $i = 1 To $Scheduledfiles[0]
        $time = FileGetTime(@WINDOWSDIR & "\Tasks\" & $Scheduledfiles[$i],1, 1)
        $now = @YEAR & @MON & @MDAY & @HOUR & @MIN
        If StringInStr(StringTrimRight($time,2),$now) Then
            FileMove(@WINDOWSDIR & "\Tasks\" & $Scheduledfiles[$i],@WINDOWSDIR & "\Tasks\" & $filename & ".job") 
        Else
            MsgBox(0,"Error","No files with the correct time code found")
            EndIf
        Next
EndIf

It won't be viewable by AT any longer.

dont need to worry about AT not finding it, but it works fine ONLY if there is at least 1 existing at?.job

if the tasks list is empty it doesnt work the first time,

second time it runs at2.job gets succesfully renamed

Share this post


Link to post
Share on other sites

I'm not sure I understand. How are you generating the AT file?


Coming soon....

Share this post


Link to post
Share on other sites

I'm not sure I understand. How are you generating the AT file?

the at file is generated with the runwait command @comspec you see

it works perfectly for at2, at3 etc

but the first time you run it, it does not rename at1.job

subsequent times you run it, it creates at2, at3 and so on and renames them perfectly

Share this post


Link to post
Share on other sites

Right, it's because of the _FileListToArray...

Hmm.. I'll try to fix it.


Coming soon....

Share this post


Link to post
Share on other sites

This is what I meant

#include <Array.au3>
#include <File.au3>
Dim $Scheduledfiles1, $Scheduledfiles2

$filename = "John"; The File name wou want.

If not FileExists (@WINDOWSDIR & "\Tasks\" & $Filename & ".job") then
    
$Scheduledfiles1 = _FileListToArray(@WINDOWSDIR & "\Tasks", "*.job")
    RunWait(@ComSpec & " /c " & "at 9:00AM /interactive C:\MPEG2Cut.exe")
$Scheduledfiles2 = _FileListToArray(@WINDOWSDIR & "\Tasks", "*.job")
    For $i = 1 To Ubound ($Scheduledfiles2) -1
        For $x = 1 To Ubound ($Scheduledfiles1) -1
            If $Scheduledfiles2[$i] <> $Scheduledfiles1[$x] then $AtFile = $Scheduledfiles2[$i]
            Next
        Next
        If not IsArray($Scheduledfiles1) Then $AtFile = $Scheduledfiles2[1]
        
        FileMove(@WINDOWSDIR & "\Tasks\" & $AtFile,@WINDOWSDIR & "\Tasks\" & $filename & ".job") 
Else
            MsgBox(0,"Schedule","Already exists")
EndIf

Share this post


Link to post
Share on other sites

Ugh, so simple! THanks. :o


Coming soon....

Share this post


Link to post
Share on other sites

Sorry no good! Still doesnt work

But, I thought about this some more, and tried to look at the much simpler approach; this might be cack handed code as I am no kind of programmer, but this bodge job seems to work perfectly :o

If FileExists(@WindowsDir & "\tasks\qbackup.job") Then FileDelete (@WindowsDir & "\tasks\qbackup.job")

$at1=0

if fileexists(@windowsdir & "\tasks\at1.job") then $at1=1

RunWait(@ComSpec & " /c " & "at " & $choicehours & ":" & $choiceminutes & " /interactive" & " /every:" & $atdays & " " & chr(34) & @scriptdir & "\qbackup.bat" & chr(34) )

$filename = "qbackup"

$Scheduledfiles = _FileListToArray(@WINDOWSDIR & "\Tasks", "at*.job")

If IsArray($Scheduledfiles) Then

For $i = 1 To $Scheduledfiles[0]

$time = FileGetTime(@WINDOWSDIR & "\Tasks\" & $Scheduledfiles[$i],1, 1)

$now = @YEAR & @MON & @MDAY & @HOUR & @MIN

If StringInStr(StringTrimRight($time,2),$now) Then

if $at1 = 1 Then FileMove(@WINDOWSDIR & "\Tasks\" & $Scheduledfiles[$i],@WINDOWSDIR & "\Tasks\" & $filename & ".job")

If $at1 = 0 Then _RunDos("ren " & @windowsdir & "\tasks\at1.job " &$filename & ".job")

Else

;;;;;;;;;

EndIf

Next

EndIf

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

#include <Array.au3>
#include <File.au3>
Dim $Scheduledfiles1, $Scheduledfiles2
$choicehours = "07"
$choiceminutes = "00"
$atdays = "m,w"

$filename = "qbackup"; The File name wou want.

If not FileExists (@WINDOWSDIR & "\Tasks\" & $Filename & ".job") then
    
$Scheduledfiles1 = _FileListToArray(@WINDOWSDIR & "\Tasks", "*.job")
    RunWait(@ComSpec & " /c " & "at " & $choicehours & ":" & $choiceminutes & " /interactive" & " /every:" & $atdays & " " & chr(34) & @scriptdir & "\qbackup.bat" & chr(34) )
$Scheduledfiles2 = _FileListToArray(@WINDOWSDIR & "\Tasks", "*.job")
    For $i = 1 To Ubound ($Scheduledfiles2) -1
        For $x = 1 To Ubound ($Scheduledfiles1) -1
            If $Scheduledfiles2[$i] <> $Scheduledfiles1[$x] then $AtFile = $Scheduledfiles2[$i]
            Next
        Next
        If not IsArray($Scheduledfiles1) Then $AtFile = $Scheduledfiles2[1]
        
        FileMove(@WINDOWSDIR & "\Tasks\" & $AtFile,@WINDOWSDIR & "\Tasks\" & $filename & ".job") 
Else
            MsgBox(0,"Schedule","Already exists")
EndIf

You can do it without that nasty Dos window too

#include <Array.au3>
#include <File.au3>
Dim $Scheduledfiles1, $Scheduledfiles2
$choicehours = "07"
$choiceminutes = "00"
$atdays = "m,w"
$Atfile = ""
$filename = "qbackup"; The File name wou want.

If not FileExists (@WINDOWSDIR & "\Tasks\" & $Filename & ".job") then
    
$Scheduledfiles1 = _FileListToArray(@WINDOWSDIR & "\Tasks", "*.job")

    RunWait("at " & $choicehours & ":" & $choiceminutes & " /interactive" & " /every:" & $atdays & " " & chr(34) & @scriptdir & "\qbackup.bat" & chr(34 ),"",@SW_hide)
$Scheduledfiles2 = _FileListToArray(@WINDOWSDIR & "\Tasks", "*.job")
    For $i = 1 To Ubound ($Scheduledfiles2) -1
        For $x = 1 To Ubound ($Scheduledfiles1) -1
            
            If $Scheduledfiles2[$i] <> $Scheduledfiles1[$x] then $AtFile = $Scheduledfiles2[$i]
        
            Next
        Next
        If not IsArray($Scheduledfiles1) Then $AtFile = $Scheduledfiles2[1]
        
        FileMove(@WINDOWSDIR & "\Tasks\" & $AtFile,@WINDOWSDIR & "\Tasks\" & $filename & ".job") 
Else
            MsgBox(0,"Schedule","Already exists")
EndIf
Edited by ChrisL

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Actually what I did before was slightly wrong because if you had at1 at2 at11 at12 already in the schedule folder from previously user created tasks it didn't work. USe this...

Edited Typo

#include <Array.au3>
#include <File.au3>
Dim $Scheduledfiles1, $Scheduledfiles2
$choicehours = "07"
$choiceminutes = "00"
$atdays = "m,w"
$Atfile = ""
$filename = "qbackup"; The File name wou want.

If Not FileExists(@WindowsDir & "\Tasks\" & $filename & ".job") Then
    
    $Scheduledfiles1 = _FileListToArray (@WindowsDir & "\Tasks", "*.job")
    RunWait("at " & $choicehours & ":" & $choiceminutes & " /interactive" & " /every:" & $atdays & " " & Chr(34) & @ScriptDir & "\qbackup.bat" & Chr(34), "", @SW_HIDE)
    $Scheduledfiles2 = _FileListToArray (@WindowsDir & "\Tasks", "*.job")
    If IsArray($Scheduledfiles1) Then
        For $i = 1 To UBound($Scheduledfiles2) - 1
            $Exist = 0
            For $x = 1 To UBound($Scheduledfiles1) - 1
                If $Scheduledfiles2[$i] = $Scheduledfiles1[$x] Then $Exist = 1
            Next
            If $Exist = 0 Then $Atfile = $Scheduledfiles2[$i]
                
        Next
    Else
        $Atfile = $Scheduledfiles2[1]
        
    EndIf
    
    FileMove(@WindowsDir & "\Tasks\" & $Atfile, @WindowsDir & "\Tasks\" & $filename & ".job")
Else
    MsgBox(0, "Schedule", "Already exists")
EndIf
Edited by ChrisL

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