setup a schedule task in WIndows XP

K

Kent

Dear all,

I want to write a batch file to set up a scheduled task in Windows XP:

1. copy a file c:\info.db to d:\ every 10 minutes
2. rename the copied file to a series by adding date time to prevent
duplication, info 091125 0810.db , info 091125 0820.db etc
3. hidden the dos windows to avoid disturbance during and after the task
execution

Thanks

Kent
 
P

Pegasus [MVP]

Kent said:
Dear all,

I want to write a batch file to set up a scheduled task in Windows XP:

1. copy a file c:\info.db to d:\ every 10 minutes
2. rename the copied file to a series by adding date time to prevent
duplication, info 091125 0810.db , info 091125 0820.db etc
3. hidden the dos windows to avoid disturbance during and after the task
execution

Thanks

Kent

Here are some suggestions:
1. Use this command: copy /y c:\info.db d:\
2. The technique depends on your local format for %date%. What is it?
3. Create a dedicated account called "Scheduler" and use it for the
scheduled task.
 
K

Kent

the date format is dd/mm/yyyy, time is hh:mm


Pegasus said:
Here are some suggestions:
1. Use this command: copy /y c:\info.db d:\
2. The technique depends on your local format for %date%. What is it?
3. Create a dedicated account called "Scheduler" and use it for the
scheduled task.
 
P

Pegasus [MVP]

You must open a Command Prompt:
- Click Start / Run
- Type the three letters cmd
- Click OK
- Type these commands and press the Enter key each time:
echo %date%
echo %time%
 
P

Pegasus [MVP]

Fine, that's the information I need. I have to go out now - you can expect a
reply in about 6 hours.
 
P

Pegasus [MVP]

Here you go:
@echo off
echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
for /F "tokens=1" %%a in ('echo %Date:-=%') do set MyDate=%%a
for /F "tokens=1-2" %%a in ('echo %Time::= %') do set MyTime=%%a%%b
echo My Date=%MyDate%, My Time=%MyTime% 1>> c:\test.txt
copy /y c:\info.db "d:\%MyDate% %MyTime%.db" 1>>c:\test.txt 2>>&1

Instructions:
1. Copy & paste the code into your batch file. Do *not* retype it.
2. Start a Command Prompt.
3. Run the batch file.
4. Examine the log file c:\test.txt. Any error messages?
5. See if the .db file got copied to drive d:.
6. Create a scheduled task to run this batch file.
7. Invoke the scheduled task.
8. Repeat points 4 and 5.
9. If all is well, remove every instance of "1>> c:\test.txt" and "2>>&1".
Note also:
- If your %date% / %time% variable suppresses leading 0s (e.g. time=9:59:12
or date=2010-2-9) then your file names will be shortened accordingly. Adding
leading 0s would make the code a little more complex.
- Having a file name of the form "YYMMDD - HHMM.db" does not guarantee you a
unique name. You can get duplicate names between 1 and 2am on the day when
Daylight Saving Time changes back to Standard Time.
- Ask if you wish to know what's behind the code.
 
K

Kent

Job invoked on 26/11/2009 Thu at 17:20
My Date=26/11/2009, My Time=1720
¨t²Î§ä¤£¨ì«ü©wªº¸ô®|¡C
½Æ»s¤F 0 ­ÓÀɮסC

From the above test.txt file found the message "invalid path, 0 file copied"
But I am sure there is a info.db in C:\, and the path D:\ exist.
When I rewrite the last sentence to
copy /y c:\info.db "d:\" 1>>c:\test.txt 2>>&1,
the file info.db can really copied to D:\, but no rename.


Kent
 
P

Pegasus [MVP]

I detect a contradiction. In your previous reply you wrote this:
- The formats are 2009-11-25 Wednesday, 18:59:01.03
In the current reply it says:
- Job invoked on 26/11/2009 Thu at 17:20

In other words, you said that you had dashes as delimiters in your date
format. The job you ran reports slashes, not dashes. I do not know what
causes the contradiction but you *must* get rid of the slashes. I also note
that the date format is DD/MM/YYYY, not YYYY-MM-DD DDDD as reported before.
This changes things considerably!
@echo off
echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
for /F "tokens=1-3" %%a in ('echo %Date:/= %') do set MyDate=%%c%%b%%a
for /F "tokens=1-2" %%a in ('echo %Time::= %') do set MyTime=%%a%%b
echo My Date=%MyDate%, My Time=%MyTime% 1>> c:\test.txt
copy /y c:\info.db "d:\%MyDate% %MyTime%.db" 1>>c:\test.txt 2>>&1
 
K

Kent

Job invoked on 27/11/2009 Fri at 9:13
My Date=20091127, My Time=913
½Æ»s¤F 1 ­ÓÀɮסC

It works now. Thank you Pegasus.
One more thing, the file names would be more consistent if the time format
is 0913 rather than 913.

Kent
 
K

Kent

I also find that the program can copy a file from c:\ to d:\,
but fails to copy from C:\Program Files\info.db to D:\.
When the space between Program & Files is deleted, it works again.
ANy idea please?
 
P

Pegasus [MVP]

There are several issues with the current script:
1. I am still puzzled about the date format discrepancies. I suspect that
you chose a date/time format for your logon account that is different from
the inbuilt default format. While this is OK for Windows, it makes the batch
file unreliable.
2. There is the issue with the leading zeros in the date/time strings which
I mentioned in my previous reply.
3. The issue with folder names having embedded spaces is easily solved by
surrounding the whole name with double quotes.
4. I am concerned about the garbage you get at the end of the log file. You
should see a message such as "1 file copied". Did you perhaps select a code
page that refers to a non-English language?

The modified script below resolves points 1..3 above. I numbered the lines
so that you can undo any line wrapping that your newsreader might cause. You
must then remove the line numbers. Do NOT retype the code - just use copy &
paste!

[01] @echo off
[02] set Scr=c:\TempVBS.vbs
[03] set VB=echo^>^>%Scr%
[04] cd 1>nul 2>%Scr%
[05] %VB% WScript.Echo Year(Date) ^& pad(Month(Date)) ^& pad(Day(Date)) ^& "
" ^& pad(Hour(Now)) ^& pad(Minute(Now))
[06] %VB% Function pad (n)
[07] %VB% pad = Right("0" ^& n, 2)
[08] %VB% End Function
[09] for /F "delims=" %%a in ('cscript //nologo %Scr%') do set DateStamp=%%a
[10] del %Scr%
[11]
[12] echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
[13] echo DateStamp=%DateStamp% 1>> c:\test.txt
[14] copy /y "c:\info.db" "d:\%DateStamp%.db" 1>>c:\test.txt 2>>&1
 
K

Kent

Pegasus, thank you for your explanation in detail.
The adding of double quotes already solved my problem.
As I am living alone, my PC need no password to log in.
However the windows schedule task needs a log in password to set up the
task.
May this password be skipped?

Kent



Pegasus said:
There are several issues with the current script:
1. I am still puzzled about the date format discrepancies. I suspect that
you chose a date/time format for your logon account that is different from
the inbuilt default format. While this is OK for Windows, it makes the
batch file unreliable.
2. There is the issue with the leading zeros in the date/time strings
which I mentioned in my previous reply.
3. The issue with folder names having embedded spaces is easily solved by
surrounding the whole name with double quotes.
4. I am concerned about the garbage you get at the end of the log file.
You should see a message such as "1 file copied". Did you perhaps select a
code page that refers to a non-English language?

The modified script below resolves points 1..3 above. I numbered the lines
so that you can undo any line wrapping that your newsreader might cause.
You must then remove the line numbers. Do NOT retype the code - just use
copy & paste!

[01] @echo off
[02] set Scr=c:\TempVBS.vbs
[03] set VB=echo^>^>%Scr%
[04] cd 1>nul 2>%Scr%
[05] %VB% WScript.Echo Year(Date) ^& pad(Month(Date)) ^& pad(Day(Date)) ^&
" " ^& pad(Hour(Now)) ^& pad(Minute(Now))
[06] %VB% Function pad (n)
[07] %VB% pad = Right("0" ^& n, 2)
[08] %VB% End Function
[09] for /F "delims=" %%a in ('cscript //nologo %Scr%') do set
DateStamp=%%a
[10] del %Scr%
[11]
[12] echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
[13] echo DateStamp=%DateStamp% 1>> c:\test.txt
[14] copy /y "c:\info.db" "d:\%DateStamp%.db" 1>>c:\test.txt 2>>&1



Kent said:
I also find that the program can copy a file from c:\ to d:\,
but fails to copy from C:\Program Files\info.db to D:\.
When the space between Program & Files is deleted, it works again.
ANy idea please?
 
P

Pegasus [MVP]

Use a dedicated account for your scheduled tasks, as I suggested in my very
first reply.


Kent said:
Pegasus, thank you for your explanation in detail.
The adding of double quotes already solved my problem.
As I am living alone, my PC need no password to log in.
However the windows schedule task needs a log in password to set up the
task.
May this password be skipped?

Kent



Pegasus said:
There are several issues with the current script:
1. I am still puzzled about the date format discrepancies. I suspect that
you chose a date/time format for your logon account that is different
from the inbuilt default format. While this is OK for Windows, it makes
the batch file unreliable.
2. There is the issue with the leading zeros in the date/time strings
which I mentioned in my previous reply.
3. The issue with folder names having embedded spaces is easily solved by
surrounding the whole name with double quotes.
4. I am concerned about the garbage you get at the end of the log file.
You should see a message such as "1 file copied". Did you perhaps select
a code page that refers to a non-English language?

The modified script below resolves points 1..3 above. I numbered the
lines so that you can undo any line wrapping that your newsreader might
cause. You must then remove the line numbers. Do NOT retype the code -
just use copy & paste!

[01] @echo off
[02] set Scr=c:\TempVBS.vbs
[03] set VB=echo^>^>%Scr%
[04] cd 1>nul 2>%Scr%
[05] %VB% WScript.Echo Year(Date) ^& pad(Month(Date)) ^& pad(Day(Date))
^& " " ^& pad(Hour(Now)) ^& pad(Minute(Now))
[06] %VB% Function pad (n)
[07] %VB% pad = Right("0" ^& n, 2)
[08] %VB% End Function
[09] for /F "delims=" %%a in ('cscript //nologo %Scr%') do set
DateStamp=%%a
[10] del %Scr%
[11]
[12] echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
[13] echo DateStamp=%DateStamp% 1>> c:\test.txt
[14] copy /y "c:\info.db" "d:\%DateStamp%.db" 1>>c:\test.txt 2>>&1



Kent said:
I also find that the program can copy a file from c:\ to d:\,
but fails to copy from C:\Program Files\info.db to D:\.
When the space between Program & Files is deleted, it works again.
ANy idea please?


"Pegasus [MVP]" <[email protected]>
¼¶¼g©ó¶l¥ó·s»D:%[email protected]...
I detect a contradiction. In your previous reply you wrote this:
- The formats are 2009-11-25 Wednesday, 18:59:01.03
In the current reply it says:
- Job invoked on 26/11/2009 Thu at 17:20

In other words, you said that you had dashes as delimiters in your date
format. The job you ran reports slashes, not dashes. I do not know what
causes the contradiction but you *must* get rid of the slashes. I also
note that the date format is DD/MM/YYYY, not YYYY-MM-DD DDDD as
reported before. This changes things considerably!
@echo off
echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
for /F "tokens=1-3" %%a in ('echo %Date:/= %') do set MyDate=%%c%%b%%a
for /F "tokens=1-2" %%a in ('echo %Time::= %') do set MyTime=%%a%%b
echo My Date=%MyDate%, My Time=%MyTime% 1>> c:\test.txt
copy /y c:\info.db "d:\%MyDate% %MyTime%.db" 1>>c:\test.txt 2>>&1


Job invoked on 26/11/2009 Thu at 17:20
My Date=26/11/2009, My Time=1720
¨t²Î§ä¤£¨ì«ü©wªº¸ô®|¡C
½Æ»s¤F 0 ­ÓÀɮסC

From the above test.txt file found the message "invalid path, 0 file
copied"
But I am sure there is a info.db in C:\, and the path D:\ exist.
When I rewrite the last sentence to
copy /y c:\info.db "d:\" 1>>c:\test.txt 2>>&1,
the file info.db can really copied to D:\, but no rename.


Kent




"Pegasus [MVP]" <[email protected]>
¼¶¼g©ó¶l¥ó·s»D:[email protected]...
Here you go:
@echo off
echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
for /F "tokens=1" %%a in ('echo %Date:-=%') do set MyDate=%%a
for /F "tokens=1-2" %%a in ('echo %Time::= %') do set MyTime=%%a%%b
echo My Date=%MyDate%, My Time=%MyTime% 1>> c:\test.txt
copy /y c:\info.db "d:\%MyDate% %MyTime%.db" 1>>c:\test.txt 2>>&1

Instructions:
1. Copy & paste the code into your batch file. Do *not* retype it.
2. Start a Command Prompt.
3. Run the batch file.
4. Examine the log file c:\test.txt. Any error messages?
5. See if the .db file got copied to drive d:.
6. Create a scheduled task to run this batch file.
7. Invoke the scheduled task.
8. Repeat points 4 and 5.
9. If all is well, remove every instance of "1>> c:\test.txt" and
"2>>&1".
Note also:
- If your %date% / %time% variable suppresses leading 0s (e.g.
time=9:59:12 or date=2010-2-9) then your file names will be shortened
accordingly. Adding leading 0s would make the code a little more
complex.
- Having a file name of the form "YYMMDD - HHMM.db" does not
guarantee you a unique name. You can get duplicate names between 1
and 2am on the day when Daylight Saving Time changes back to Standard
Time.
- Ask if you wish to know what's behind the code.


I see.
The formats are 2009-11-25 Wednesday, 18:59:01.03



"Pegasus [MVP]" <[email protected]>
?¤J®ø®§·s?:[email protected]...
You must open a Command Prompt:
- Click Start / Run
- Type the three letters cmd
- Click OK
- Type these commands and press the Enter key each time:
echo %date%
echo %time%


How can I indentify the local format of %date% please?



"Pegasus [MVP]" <[email protected]>
?¤J®ø®§·s?:%[email protected]...
Is it really dd/mm/yyyy? Isn't there a DOW somewhere?

the date format is dd/mm/yyyy, time is hh:mm


"Pegasus [MVP]" <[email protected]>
?¤J®ø®§·s?:%[email protected]...

Dear all,

I want to write a batch file to set up a scheduled task in
Windows XP:

1. copy a file c:\info.db to d:\ every 10 minutes
2. rename the copied file to a series by adding date time to
prevent duplication, info 091125 0810.db , info 091125 0820.db
etc
3. hidden the dos windows to avoid disturbance during and
after the task execution

Thanks

Kent

Here are some suggestions:
1. Use this command: copy /y c:\info.db d:\
2. The technique depends on your local format for %date%. What
is it?
3. Create a dedicated account called "Scheduler" and use it for
the scheduled task.
 
K

Kent

I got it, thanks Pegasus.
Your help me so much

Kent



Pegasus said:
Use a dedicated account for your scheduled tasks, as I suggested in my
very first reply.


Kent said:
Pegasus, thank you for your explanation in detail.
The adding of double quotes already solved my problem.
As I am living alone, my PC need no password to log in.
However the windows schedule task needs a log in password to set up the
task.
May this password be skipped?

Kent



Pegasus said:
There are several issues with the current script:
1. I am still puzzled about the date format discrepancies. I suspect
that you chose a date/time format for your logon account that is
different from the inbuilt default format. While this is OK for Windows,
it makes the batch file unreliable.
2. There is the issue with the leading zeros in the date/time strings
which I mentioned in my previous reply.
3. The issue with folder names having embedded spaces is easily solved
by surrounding the whole name with double quotes.
4. I am concerned about the garbage you get at the end of the log file.
You should see a message such as "1 file copied". Did you perhaps select
a code page that refers to a non-English language?

The modified script below resolves points 1..3 above. I numbered the
lines so that you can undo any line wrapping that your newsreader might
cause. You must then remove the line numbers. Do NOT retype the code -
just use copy & paste!

[01] @echo off
[02] set Scr=c:\TempVBS.vbs
[03] set VB=echo^>^>%Scr%
[04] cd 1>nul 2>%Scr%
[05] %VB% WScript.Echo Year(Date) ^& pad(Month(Date)) ^& pad(Day(Date))
^& " " ^& pad(Hour(Now)) ^& pad(Minute(Now))
[06] %VB% Function pad (n)
[07] %VB% pad = Right("0" ^& n, 2)
[08] %VB% End Function
[09] for /F "delims=" %%a in ('cscript //nologo %Scr%') do set
DateStamp=%%a
[10] del %Scr%
[11]
[12] echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
[13] echo DateStamp=%DateStamp% 1>> c:\test.txt
[14] copy /y "c:\info.db" "d:\%DateStamp%.db" 1>>c:\test.txt 2>>&1



I also find that the program can copy a file from c:\ to d:\,
but fails to copy from C:\Program Files\info.db to D:\.
When the space between Program & Files is deleted, it works again.
ANy idea please?


"Pegasus [MVP]" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:%[email protected]...
I detect a contradiction. In your previous reply you wrote this:
- The formats are 2009-11-25 Wednesday, 18:59:01.03
In the current reply it says:
- Job invoked on 26/11/2009 Thu at 17:20

In other words, you said that you had dashes as delimiters in your
date format. The job you ran reports slashes, not dashes. I do not
know what causes the contradiction but you *must* get rid of the
slashes. I also note that the date format is DD/MM/YYYY, not
YYYY-MM-DD DDDD as reported before. This changes things considerably!
@echo off
echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
for /F "tokens=1-3" %%a in ('echo %Date:/= %') do set MyDate=%%c%%b%%a
for /F "tokens=1-2" %%a in ('echo %Time::= %') do set MyTime=%%a%%b
echo My Date=%MyDate%, My Time=%MyTime% 1>> c:\test.txt
copy /y c:\info.db "d:\%MyDate% %MyTime%.db" 1>>c:\test.txt 2>>&1


Job invoked on 26/11/2009 Thu at 17:20
My Date=26/11/2009, My Time=1720
¨t²Î§ä¤£¨ì«ü©wªº¸ô®|¡C
½Æ»s¤F 0 ­ÓÀɮסC

From the above test.txt file found the message "invalid path, 0 file
copied"
But I am sure there is a info.db in C:\, and the path D:\ exist.
When I rewrite the last sentence to
copy /y c:\info.db "d:\" 1>>c:\test.txt 2>>&1,
the file info.db can really copied to D:\, but no rename.


Kent




"Pegasus [MVP]" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:[email protected]...
Here you go:
@echo off
echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
for /F "tokens=1" %%a in ('echo %Date:-=%') do set MyDate=%%a
for /F "tokens=1-2" %%a in ('echo %Time::= %') do set MyTime=%%a%%b
echo My Date=%MyDate%, My Time=%MyTime% 1>> c:\test.txt
copy /y c:\info.db "d:\%MyDate% %MyTime%.db" 1>>c:\test.txt 2>>&1

Instructions:
1. Copy & paste the code into your batch file. Do *not* retype it.
2. Start a Command Prompt.
3. Run the batch file.
4. Examine the log file c:\test.txt. Any error messages?
5. See if the .db file got copied to drive d:.
6. Create a scheduled task to run this batch file.
7. Invoke the scheduled task.
8. Repeat points 4 and 5.
9. If all is well, remove every instance of "1>> c:\test.txt" and
"2>>&1".
Note also:
- If your %date% / %time% variable suppresses leading 0s (e.g.
time=9:59:12 or date=2010-2-9) then your file names will be
shortened accordingly. Adding leading 0s would make the code a
little more complex.
- Having a file name of the form "YYMMDD - HHMM.db" does not
guarantee you a unique name. You can get duplicate names between 1
and 2am on the day when Daylight Saving Time changes back to
Standard Time.
- Ask if you wish to know what's behind the code.


I see.
The formats are 2009-11-25 Wednesday, 18:59:01.03



"Pegasus [MVP]" <[email protected]> ?¤J®ø®§·s?:[email protected]...
You must open a Command Prompt:
- Click Start / Run
- Type the three letters cmd
- Click OK
- Type these commands and press the Enter key each time:
echo %date%
echo %time%


How can I indentify the local format of %date% please?



"Pegasus [MVP]" <[email protected]> ?¤J®ø®§·s?:%[email protected]...
Is it really dd/mm/yyyy? Isn't there a DOW somewhere?

the date format is dd/mm/yyyy, time is hh:mm


"Pegasus [MVP]" <[email protected]> ?¤J®ø®§·s?:%[email protected]...

Dear all,

I want to write a batch file to set up a scheduled task in
Windows XP:

1. copy a file c:\info.db to d:\ every 10 minutes
2. rename the copied file to a series by adding date time to
prevent duplication, info 091125 0810.db , info 091125
0820.db etc
3. hidden the dos windows to avoid disturbance during and
after the task execution

Thanks

Kent

Here are some suggestions:
1. Use this command: copy /y c:\info.db d:\
2. The technique depends on your local format for %date%. What
is it?
3. Create a dedicated account called "Scheduler" and use it
for the scheduled task.
 
K

kent

Dear Pegasus

Actually I am not sure how to create that dedicated account.

Now I have only a log in account without using password. When I create a so
call "Scheduler" account, my PC requires me to select an account to log in
and key in password. But I prefer go straight into windows without log in as
now what I am doing.

Kent



Pegasus said:
Use a dedicated account for your scheduled tasks, as I suggested in my
very first reply.


Kent said:
Pegasus, thank you for your explanation in detail.
The adding of double quotes already solved my problem.
As I am living alone, my PC need no password to log in.
However the windows schedule task needs a log in password to set up the
task.
May this password be skipped?

Kent



Pegasus said:
There are several issues with the current script:
1. I am still puzzled about the date format discrepancies. I suspect
that you chose a date/time format for your logon account that is
different from the inbuilt default format. While this is OK for Windows,
it makes the batch file unreliable.
2. There is the issue with the leading zeros in the date/time strings
which I mentioned in my previous reply.
3. The issue with folder names having embedded spaces is easily solved
by surrounding the whole name with double quotes.
4. I am concerned about the garbage you get at the end of the log file.
You should see a message such as "1 file copied". Did you perhaps select
a code page that refers to a non-English language?

The modified script below resolves points 1..3 above. I numbered the
lines so that you can undo any line wrapping that your newsreader might
cause. You must then remove the line numbers. Do NOT retype the code -
just use copy & paste!

[01] @echo off
[02] set Scr=c:\TempVBS.vbs
[03] set VB=echo^>^>%Scr%
[04] cd 1>nul 2>%Scr%
[05] %VB% WScript.Echo Year(Date) ^& pad(Month(Date)) ^& pad(Day(Date))
^& " " ^& pad(Hour(Now)) ^& pad(Minute(Now))
[06] %VB% Function pad (n)
[07] %VB% pad = Right("0" ^& n, 2)
[08] %VB% End Function
[09] for /F "delims=" %%a in ('cscript //nologo %Scr%') do set
DateStamp=%%a
[10] del %Scr%
[11]
[12] echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
[13] echo DateStamp=%DateStamp% 1>> c:\test.txt
[14] copy /y "c:\info.db" "d:\%DateStamp%.db" 1>>c:\test.txt 2>>&1



I also find that the program can copy a file from c:\ to d:\,
but fails to copy from C:\Program Files\info.db to D:\.
When the space between Program & Files is deleted, it works again.
ANy idea please?


"Pegasus [MVP]" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:%[email protected]...
I detect a contradiction. In your previous reply you wrote this:
- The formats are 2009-11-25 Wednesday, 18:59:01.03
In the current reply it says:
- Job invoked on 26/11/2009 Thu at 17:20

In other words, you said that you had dashes as delimiters in your
date format. The job you ran reports slashes, not dashes. I do not
know what causes the contradiction but you *must* get rid of the
slashes. I also note that the date format is DD/MM/YYYY, not
YYYY-MM-DD DDDD as reported before. This changes things considerably!
@echo off
echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
for /F "tokens=1-3" %%a in ('echo %Date:/= %') do set MyDate=%%c%%b%%a
for /F "tokens=1-2" %%a in ('echo %Time::= %') do set MyTime=%%a%%b
echo My Date=%MyDate%, My Time=%MyTime% 1>> c:\test.txt
copy /y c:\info.db "d:\%MyDate% %MyTime%.db" 1>>c:\test.txt 2>>&1


Job invoked on 26/11/2009 Thu at 17:20
My Date=26/11/2009, My Time=1720
¨t²Î§ä¤£¨ì«ü©wªº¸ô®|¡C
½Æ»s¤F 0 ­ÓÀɮסC

From the above test.txt file found the message "invalid path, 0 file
copied"
But I am sure there is a info.db in C:\, and the path D:\ exist.
When I rewrite the last sentence to
copy /y c:\info.db "d:\" 1>>c:\test.txt 2>>&1,
the file info.db can really copied to D:\, but no rename.


Kent




"Pegasus [MVP]" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:[email protected]...
Here you go:
@echo off
echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
for /F "tokens=1" %%a in ('echo %Date:-=%') do set MyDate=%%a
for /F "tokens=1-2" %%a in ('echo %Time::= %') do set MyTime=%%a%%b
echo My Date=%MyDate%, My Time=%MyTime% 1>> c:\test.txt
copy /y c:\info.db "d:\%MyDate% %MyTime%.db" 1>>c:\test.txt 2>>&1

Instructions:
1. Copy & paste the code into your batch file. Do *not* retype it.
2. Start a Command Prompt.
3. Run the batch file.
4. Examine the log file c:\test.txt. Any error messages?
5. See if the .db file got copied to drive d:.
6. Create a scheduled task to run this batch file.
7. Invoke the scheduled task.
8. Repeat points 4 and 5.
9. If all is well, remove every instance of "1>> c:\test.txt" and
"2>>&1".
Note also:
- If your %date% / %time% variable suppresses leading 0s (e.g.
time=9:59:12 or date=2010-2-9) then your file names will be
shortened accordingly. Adding leading 0s would make the code a
little more complex.
- Having a file name of the form "YYMMDD - HHMM.db" does not
guarantee you a unique name. You can get duplicate names between 1
and 2am on the day when Daylight Saving Time changes back to
Standard Time.
- Ask if you wish to know what's behind the code.


I see.
The formats are 2009-11-25 Wednesday, 18:59:01.03



"Pegasus [MVP]" <[email protected]> ?¤J®ø®§·s?:[email protected]...
You must open a Command Prompt:
- Click Start / Run
- Type the three letters cmd
- Click OK
- Type these commands and press the Enter key each time:
echo %date%
echo %time%


How can I indentify the local format of %date% please?



"Pegasus [MVP]" <[email protected]> ?¤J®ø®§·s?:%[email protected]...
Is it really dd/mm/yyyy? Isn't there a DOW somewhere?

the date format is dd/mm/yyyy, time is hh:mm


"Pegasus [MVP]" <[email protected]> ?¤J®ø®§·s?:%[email protected]...

Dear all,

I want to write a batch file to set up a scheduled task in
Windows XP:

1. copy a file c:\info.db to d:\ every 10 minutes
2. rename the copied file to a series by adding date time to
prevent duplication, info 091125 0810.db , info 091125
0820.db etc
3. hidden the dos windows to avoid disturbance during and
after the task execution

Thanks

Kent

Here are some suggestions:
1. Use this command: copy /y c:\info.db d:\
2. The technique depends on your local format for %date%. What
is it?
3. Create a dedicated account called "Scheduler" and use it
for the scheduled task.
 
J

Jose

Dear Pegasus

Actually I am not sure how to create that dedicated account.

Now I have only a log in account without using password. When I create a so
call "Scheduler" account, my PC requires me to select  an account to log in
and key in password. But I prefer go straight into windows without log inas
now what I am doing.

Kent

"Pegasus [MVP]" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:u02%[email protected]...


Use a dedicated account for your scheduled tasks, as I suggested in my
very first reply.
Kent said:
Pegasus, thank you for your explanation in detail.
The adding of double quotes already solved my problem.
As I am living alone, my PC need no password to log in.
However the windows schedule task needs a log in password to set up the
task.
May this password be skipped?
Kent
"Pegasus [MVP]" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:[email protected]...
There are several issues with the current script:
1. I am still puzzled about the date format discrepancies. I suspect
that you chose a date/time format for your logon account that is
different from the inbuilt default format. While this is OK for Windows,
it makes the batch file unreliable.
2. There is the issue with the leading zeros in the date/time strings
which I mentioned in my previous reply.
3. The issue with folder names having embedded spaces is easily solved
by surrounding the whole name with double quotes.
4. I am concerned about the garbage you get at the end of the log file.
You should see a message such as "1 file copied". Did you perhaps select
a code page that refers to a non-English language?
The modified script below resolves points 1..3 above. I numbered the
lines so that you can undo any line wrapping that your newsreader might
cause. You must then remove the line numbers. Do NOT retype the code -
just use copy & paste!
[01] @echo off
[02] set Scr=c:\TempVBS.vbs
[03] set VB=echo^>^>%Scr%
[04] cd 1>nul 2>%Scr%
[05] %VB% WScript.Echo Year(Date) ^& pad(Month(Date)) ^& pad(Day(Date))
^& " " ^& pad(Hour(Now)) ^& pad(Minute(Now))
[06] %VB% Function pad (n)
[07] %VB%   pad = Right("0" ^& n, 2)
[08] %VB% End Function
[09] for /F "delims=" %%a in ('cscript //nologo %Scr%') do set
DateStamp=%%a
[10] del %Scr%
[11]
[12] echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
[13] echo DateStamp=%DateStamp% 1>> c:\test.txt
[14] copy /y "c:\info.db" "d:\%DateStamp%.db" 1>>c:\test.txt 2>>&1
I also find that the program can copy a file from c:\ to d:\,
but fails to copy from C:\Program Files\info.db to D:\.
When the space between Program & Files is deleted, it works again.
ANy idea please?
"Pegasus [MVP]" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:%[email protected]...
I detect a contradiction. In your previous reply you wrote this:
- The formats are 2009-11-25 Wednesday, 18:59:01.03
In the current reply it says:
- Job invoked on 26/11/2009 Thu at 17:20
In other words, you said that you had dashes as delimiters in your
date format. The job you ran reports slashes, not dashes. I do not
know what causes the contradiction but you *must* get rid of the
slashes. I also note that the date format is DD/MM/YYYY, not
YYYY-MM-DD DDDD as reported before. This changes things considerably!
@echo off
echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
for /F "tokens=1-3" %%a in ('echo %Date:/= %') do set MyDate=%%c%%b%%a
for /F "tokens=1-2" %%a in ('echo %Time::= %') do set MyTime=%%a%%b
echo My Date=%MyDate%, My Time=%MyTime% 1>> c:\test.txt
copy /y c:\info.db "d:\%MyDate% %MyTime%.db" 1>>c:\test.txt 2>>&1
Job invoked on 26/11/2009 Thu at 17:20
My Date=26/11/2009, My Time=1720
¨t²Î§ä¤£¨ì«ü©wªº¸ô®|¡C
½Æ»s¤F         0 ­ÓÀɮסC
From the above test.txt file found the message "invalid path, 0 file
copied"
But I am sure there is a info.db in C:\, and the path D:\ exist.
When I rewrite the last sentence to
copy /y c:\info.db "d:\" 1>>c:\test.txt 2>>&1,
the file info.db can really copied to D:\, but no rename.
Kent
"Pegasus [MVP]" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:[email protected]...
Here you go:
@echo off
echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
for /F "tokens=1"   %%a in ('echo %Date:-=%') do set MyDate=%%a
for /F "tokens=1-2" %%a in ('echo %Time::= %') do set MyTime=%%a%%b
echo My Date=%MyDate%, My Time=%MyTime% 1>> c:\test.txt
copy /y c:\info.db "d:\%MyDate% %MyTime%.db" 1>>c:\test.txt 2>>&1
Instructions:
1. Copy & paste the code into your batch file. Do *not* retype it..
2. Start a Command Prompt.
3. Run the batch file.
4. Examine the log file c:\test.txt. Any error messages?
5. See if the .db file got copied to drive d:.
6. Create a scheduled task to run this batch file.
7. Invoke the scheduled task.
8. Repeat points 4 and 5.
9. If all is well, remove every instance of "1>> c:\test.txt" and
"2>>&1".
Note also:
- If your %date% / %time% variable suppresses leading 0s (e.g.
time=9:59:12 or date=2010-2-9) then your file names will be
shortened accordingly. Adding leading 0s would make the code a
little more complex.
- Having a file name of the form "YYMMDD - HHMM.db" does not
guarantee you a unique name. You can get duplicate names between 1
and 2am on the day when Daylight Saving Time changes back to
Standard Time.
- Ask if you wish to know what's behind the code.
I see.
The formats are 2009-11-25 Wednesday, 18:59:01.03
"Pegasus [MVP]" <[email protected]> ?¤J®ø®§·s?:[email protected]...
You must open a Command Prompt:
- Click Start / Run
- Type the three letters  cmd
- Click OK
- Type these commands and press the Enter key each time:
echo %date%
echo %time%
How can I indentify the local format of %date% please?
"Pegasus [MVP]" <[email protected]> ?¤J®ø®§·s?:%[email protected]...
Is it really dd/mm/yyyy? Isn't there a DOW somewhere?
the date format is dd/mm/yyyy, time is hh:mm
"Pegasus [MVP]" <[email protected]> ?¤J®ø®§·s?:%[email protected]...
Dear all,
I want to write a batch file to set up a scheduled task in
Windows XP:
1. copy a file c:\info.db to d:\ every 10 minutes
2. rename the copied file to a series by adding date time to
prevent duplication, info 091125 0810.db , info 091125
0820.db etc
3. hidden the dos windows to avoid disturbance during and
after the task execution
Thanks
Kent
Here are some suggestions:
1. Use this command: copy /y c:\info.db d:\
2. The technique depends on your local format for %date%. What
is it?
3. Create a dedicated account called "Scheduler" and use it
for the scheduled task.

Maybe Pegasus has the day off.

Here is a link describing two methods to login automatically:

http://windowsxp.mvps.org/Autologon.htm

Tweak UI is a popular tool that will let you accomplish your mission
and has some other things in it you may like:

http://www.microsoft.com/windowsxp/downloads/Powertoys/xppowertoys.mspx
 
K

kent

Dear Jose,

Thank you for your hints
I have sloved the problem by using control userpasswords2

Kent



"Jose" <[email protected]>
???????:9fb532d4-4401-4e49-bf23-7334e9f70223@d20g2000yqh.googlegroups.com...
Dear Pegasus

Actually I am not sure how to create that dedicated account.

Now I have only a log in account without using password. When I create a
so
call "Scheduler" account, my PC requires me to select an account to log in
and key in password. But I prefer go straight into windows without log in
as
now what I am doing.

Kent

"Pegasus [MVP]" <[email protected]>
¼¶¼g©ó¶l¥ó·s»D:u02%[email protected]...


Use a dedicated account for your scheduled tasks, as I suggested in my
very first reply.
Kent said:
Pegasus, thank you for your explanation in detail.
The adding of double quotes already solved my problem.
As I am living alone, my PC need no password to log in.
However the windows schedule task needs a log in password to set up the
task.
May this password be skipped?
Kent
"Pegasus [MVP]" <[email protected]>
¼¶¼g©ó¶l¥ó·s»D:[email protected]...
There are several issues with the current script:
1. I am still puzzled about the date format discrepancies. I suspect
that you chose a date/time format for your logon account that is
different from the inbuilt default format. While this is OK for
Windows,
it makes the batch file unreliable.
2. There is the issue with the leading zeros in the date/time strings
which I mentioned in my previous reply.
3. The issue with folder names having embedded spaces is easily solved
by surrounding the whole name with double quotes.
4. I am concerned about the garbage you get at the end of the log
file.
You should see a message such as "1 file copied". Did you perhaps
select
a code page that refers to a non-English language?
The modified script below resolves points 1..3 above. I numbered the
lines so that you can undo any line wrapping that your newsreader
might
cause. You must then remove the line numbers. Do NOT retype the code -
just use copy & paste!
[01] @echo off
[02] set Scr=c:\TempVBS.vbs
[03] set VB=echo^>^>%Scr%
[04] cd 1>nul 2>%Scr%
[05] %VB% WScript.Echo Year(Date) ^& pad(Month(Date)) ^&
pad(Day(Date))
^& " " ^& pad(Hour(Now)) ^& pad(Minute(Now))
[06] %VB% Function pad (n)
[07] %VB% pad = Right("0" ^& n, 2)
[08] %VB% End Function
[09] for /F "delims=" %%a in ('cscript //nologo %Scr%') do set
DateStamp=%%a
[10] del %Scr%
[11]
[12] echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
[13] echo DateStamp=%DateStamp% 1>> c:\test.txt
[14] copy /y "c:\info.db" "d:\%DateStamp%.db" 1>>c:\test.txt 2>>&1
I also find that the program can copy a file from c:\ to d:\,
but fails to copy from C:\Program Files\info.db to D:\.
When the space between Program & Files is deleted, it works again.
ANy idea please?
"Pegasus [MVP]" <[email protected]>
¼¶¼g©ó¶l¥ó·s»D:%[email protected]...
I detect a contradiction. In your previous reply you wrote this:
- The formats are 2009-11-25 Wednesday, 18:59:01.03
In the current reply it says:
- Job invoked on 26/11/2009 Thu at 17:20
In other words, you said that you had dashes as delimiters in your
date format. The job you ran reports slashes, not dashes. I do not
know what causes the contradiction but you *must* get rid of the
slashes. I also note that the date format is DD/MM/YYYY, not
YYYY-MM-DD DDDD as reported before. This changes things
considerably!
@echo off
echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
for /F "tokens=1-3" %%a in ('echo %Date:/= %') do set
MyDate=%%c%%b%%a
for /F "tokens=1-2" %%a in ('echo %Time::= %') do set MyTime=%%a%%b
echo My Date=%MyDate%, My Time=%MyTime% 1>> c:\test.txt
copy /y c:\info.db "d:\%MyDate% %MyTime%.db" 1>>c:\test.txt 2>>&1
Job invoked on 26/11/2009 Thu at 17:20
My Date=26/11/2009, My Time=1720
¨t²Î§ä¤£¨ì«ü©wªº¸ô®|¡C
½Æ»s¤F 0 ­ÓÀɮסC
From the above test.txt file found the message "invalid path, 0
file
copied"
But I am sure there is a info.db in C:\, and the path D:\ exist.
When I rewrite the last sentence to
copy /y c:\info.db "d:\" 1>>c:\test.txt 2>>&1,
the file info.db can really copied to D:\, but no rename.
Kent
"Pegasus [MVP]" <[email protected]>
¼¶¼g©ó¶l¥ó·s»D:[email protected]...
Here you go:
@echo off
echo Job invoked on %date% at %time:~0,5% 1>> c:\test.txt
for /F "tokens=1" %%a in ('echo %Date:-=%') do set MyDate=%%a
for /F "tokens=1-2" %%a in ('echo %Time::= %') do set
MyTime=%%a%%b
echo My Date=%MyDate%, My Time=%MyTime% 1>> c:\test.txt
copy /y c:\info.db "d:\%MyDate% %MyTime%.db" 1>>c:\test.txt 2>>&1
Instructions:
1. Copy & paste the code into your batch file. Do *not* retype it.
2. Start a Command Prompt.
3. Run the batch file.
4. Examine the log file c:\test.txt. Any error messages?
5. See if the .db file got copied to drive d:.
6. Create a scheduled task to run this batch file.
7. Invoke the scheduled task.
8. Repeat points 4 and 5.
9. If all is well, remove every instance of "1>> c:\test.txt" and
"2>>&1".
Note also:
- If your %date% / %time% variable suppresses leading 0s (e.g.
time=9:59:12 or date=2010-2-9) then your file names will be
shortened accordingly. Adding leading 0s would make the code a
little more complex.
- Having a file name of the form "YYMMDD - HHMM.db" does not
guarantee you a unique name. You can get duplicate names between 1
and 2am on the day when Daylight Saving Time changes back to
Standard Time.
- Ask if you wish to know what's behind the code.
I see.
The formats are 2009-11-25 Wednesday, 18:59:01.03
"Pegasus [MVP]" <[email protected]>
?¤J®ø®§·s?:[email protected]...
You must open a Command Prompt:
- Click Start / Run
- Type the three letters cmd
- Click OK
- Type these commands and press the Enter key each time:
echo %date%
echo %time%
How can I indentify the local format of %date% please?
"Pegasus [MVP]" <[email protected]>
?¤J®ø®§·s?:%[email protected]...
Is it really dd/mm/yyyy? Isn't there a DOW somewhere?
the date format is dd/mm/yyyy, time is hh:mm
"Pegasus [MVP]" <[email protected]>
?¤J®ø®§·s?:%[email protected]...
Dear all,
I want to write a batch file to set up a scheduled task in
Windows XP:
1. copy a file c:\info.db to d:\ every 10 minutes
2. rename the copied file to a series by adding date time
to
prevent duplication, info 091125 0810.db , info 091125
0820.db etc
3. hidden the dos windows to avoid disturbance during and
after the task execution
Thanks
Kent
Here are some suggestions:
1. Use this command: copy /y c:\info.db d:\
2. The technique depends on your local format for %date%.
What
is it?
3. Create a dedicated account called "Scheduler" and use it
for the scheduled task.

Maybe Pegasus has the day off.

Here is a link describing two methods to login automatically:

http://windowsxp.mvps.org/Autologon.htm

Tweak UI is a popular tool that will let you accomplish your mission
and has some other things in it you may like:

http://www.microsoft.com/windowsxp/downloads/Powertoys/xppowertoys.mspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top