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.
"Pegasus [MVP]" <ne...@microsoft.com> ?�J��s?:%23BowrTa...@TK2MSFTNGP04.phx.gbl...
"Kent" <ke...@micrsoft.com> wrote in message
news:%23B7Moka...@TK2MSFTNGP02.phx.gbl...
"Pegasus [MVP]" <ne...@microsoft.com> ?�J��s?:%23KTrkIb...@TK2MSFTNGP04.phx.gbl...
"Kent" <ke...@micrsoft.com> wrote in message
news:uR76Habb...@TK2MSFTNGP02.phx.gbl...
"Pegasus [MVP]" <ne...@microsoft.com> ?�J��s?:uvuhCrbb...@TK2MSFTNGP02.phx.gbl...
"Kent" <ke...@micrsoft.com> wrote in message
news:OHkh15bb...@TK2MSFTNGP06.phx.gbl...
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.
"Kent" <ke...@micrsoft.com> wrote in message
news:OHkh15bb...@TK2MSFTNGP06.phx.gbl...
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]" <ne...@microsoft.com> ���g��l��s�D:OMCursfb...@TK2MSFTNGP05.phx.gbl...
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
"Kent" <kft...@gmail.com> wrote in message
news:etfNSqnb...@TK2MSFTNGP04.phx.gbl...
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
"Pegasus [MVP]" <ne...@microsoft.com> ���g��l��s�D:%23CNuc1p...@TK2MSFTNGP04.phx.gbl...
"Pegasus [MVP]" <ne...@microsoft.com> ���g��l��s�D:%23CNuc1p...@TK2MSFTNGP04.phx.gbl...
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" <kft...@gmail.com> wrote in message
news:u$bfVlybK...@TK2MSFTNGP05.phx.gbl...
Kent
"Pegasus [MVP]" <ne...@microsoft.com> ���g��l��s�D:ezgvr90b...@TK2MSFTNGP04.phx.gbl...
"Kent" <kft...@gmail.com> wrote in message
news:OWPLZwVc...@TK2MSFTNGP02.phx.gbl...
Kent
"Pegasus [MVP]" <ne...@microsoft.com> ���g��l��s�D:u02%23NdYcK...@TK2MSFTNGP06.phx.gbl...
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]" <ne...@microsoft.com> ���g��l��s�D:u02%23NdYcK...@TK2MSFTNGP06.phx.gbl...
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
Thank you for your hints
I have sloved the problem by using control userpasswords2
Kent
"Jose" <jose...@yahoo.com>
???????:9fb532d4-4401-4e49...@d20g2000yqh.googlegroups.com...
On Dec 24, 12:07 pm, "kent" <kf...@gmail.com> wrote:
> 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]" <n...@microsoft.com>
> ���g��l��s�D:u02%23NdYcKHA.1...@TK2MSFTNGP06.phx.gbl...
>
>
>
> > Use a dedicated account for your scheduled tasks, as I suggested in my
> > very first reply.
>
> > "Kent" <kft...@gmail.com> wrote in message
> >news:OWPLZwVc...@TK2MSFTNGP02.phx.gbl...
> >> 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]" <n...@microsoft.com>
> >> ���g��l��s�D:ezgvr90bKHA.4...@TK2MSFTNGP04.phx.gbl...
> >>>> ���g��l��s�D:%23CNuc1pbKHA.2...@TK2MSFTNGP04.phx.gbl...
> >>>>>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
>
> >>>>> "Kent" <kft...@gmail.com> wrote in message
> >>>>>news:etfNSqnb...@TK2MSFTNGP04.phx.gbl...
> >>>>>> 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]" <n...@microsoft.com>
> >>>>>> ���g��l��s�D:OMCursfbKHA.5...@TK2MSFTNGP05.phx.gbl...
> >>>>>>>> ?�J��s?:uvuhCrbbKHA.5...@TK2MSFTNGP02.phx.gbl...
> >>>>>>>>> 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%
>
> >>>>>>>>> "Kent" <k...@micrsoft.com> wrote in message
> >>>>>>>>>news:uR76Habb...@TK2MSFTNGP02.phx.gbl...
> >>>>>>>>>> How can I indentify the local format of %date% please?
>
> >>>>>>>>>> "Pegasus [MVP]" <n...@microsoft.com>
> >>>>>>>>>> ?�J��s?:%23KTrkIbbKHA.4...@TK2MSFTNGP04.phx.gbl...
> >>>>>>>>>>> Is it really dd/mm/yyyy? Isn't there a DOW somewhere?
>
> >>>>>>>>>>> "Kent" <k...@micrsoft.com> wrote in message
> >>>>>>>>>>>news:%23B7Moka...@TK2MSFTNGP02.phx.gbl...
> >>>>>>>>>>>> the date format is dd/mm/yyyy, time is hh:mm
>
> >>>>>>>>>>>> "Pegasus [MVP]" <n...@microsoft.com>
> >>>>>>>>>>>> ?�J��s?:%23BowrTabKHA.2...@TK2MSFTNGP04.phx.gbl...
Good job.