PC Review


Reply
Thread Tools Rate Thread

Batch file not working as a scheduled task

 
 
David
Guest
Posts: n/a
 
      8th Oct 2003
Not strictly a command prompt problem I know, but not sure where else to look.

Running Windows 2000 SP2

The batch file works just fine when started outside of the scheduled
tasks, but when run as a scheduled task it fails.
I believe it is a problem with the Command Extensions - ie. my batch
file is using them, and they are not enabled. I get the following
errors :

'date /t' is not recognized as an internal or external command,
operable program or batch file.
'time /t' is not recognized as an internal or external command,
operable program or batch file.

The lines are :

for /f "tokens=1,2,3,4* delims=/ " %%K in ('date /t') do set day=%%L &
set month=%%M & set year=%%N
for /f "tokens=1,2 delims=: " %%T in ('time /t') do set hour=%%T & set
minute=%%U

It's an inherited script, and I have evidence of it working in the
past. I have a suspicion that SP2 has been applied since that time.

The ultimate goal is to rename a file with a time and date included
before archiving it. If there is an alternative way then I'm more
than happy to ditch what I've got now!!

TIA
David.
 
Reply With Quote
 
 
 
 
Ritchie
Guest
Posts: n/a
 
      8th Oct 2003
"David" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> I believe it is a problem with the Command Extensions - ie. my batch
> file is using them, and they are not enabled. I get the following
> errors :


You can turn them on by adding 'setlocal ENABLEEXTENSIONS' to your
batch file, something like:-

@echo off & setlocal ENABLEEXTENSIONS

The method you're currently using to load date and time components into
variables is highly reliant the regional settings and delimiters used.
This is definitely not a good idea especially if the script is to run
on other machines. Here's a more reliable way (but I'm not your dad <g>)

01. @echo off & setlocal ENABLEEXTENSIONS
02. call :GetTime h n s t
03. call :GetDate y d m
04. echo/Today is: %y%-%m%-%d% %h%:%n%:%s%
05. goto :EOF
06.
07. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
08. :GetTime hh nn ss tt
09. ::
10. :: By: Ritchie Lawrence, updated 2002-10-30. Version 1.2
11. ::
12. :: Func: Loads local system time components into args 1 to 4.
13. :: For NT4/2K/XP/2003
14. ::
15. :: Args: %1 Var to receive hours, 2 digits, 00 to 23 (by ref)
16. :: %2 Var to receive minutes, 2 digits, 00 to 59 (by ref)
17. :: %3 Var to receive seconds, 2 digits, 00 to 59 (by ref)
18. :: %4 Var to receive centiseconds, 2 digits, 00 to 99 (by ref)
19. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
20. setlocal ENABLEEXTENSIONS
21. for /f "tokens=5-8 delims=:. " %%a in ('echo/^|time') do (
22. set hh=%%a&set nn=%%b&set ss=%%c&set cs=%%d)
23. if 1%hh% LSS 20 set hh=0%hh%
24. endlocal&set %1=%hh%&set %2=%nn%&set %3=%ss%&set %4=%cs%&goto :EOF
25. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
26.
27. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
28. :GetDate yy mm dd
29. ::
30. :: By: Ritchie Lawrence, 2002-06-15. Version 1.0
31. ::
32. :: Func: Loads local system date components into args 1 to 3.
33. :: For NT4/2000/XP/2003.
34. ::
35. :: Args: %1 var to receive year, 4 digits (by ref)
36. :: %2 var to receive month, 2 digits, 01 to 12 (by ref)
37. :: %3 Var to receive day of month, 2 digits, 01 to 31 (by ref)
38. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
39. setlocal ENABLEEXTENSIONS
40. set t=2&if "%date%z" LSS "A" set t=1
41. for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
42. for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
43. set %%a=%%d&set %%b=%%e&set %%c=%%f))
44. endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
45. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

--
Ritchie, undo for mail





 
Reply With Quote
 
Ritchie
Guest
Posts: n/a
 
      8th Oct 2003
"David" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> The batch file works just fine when started outside of the scheduled
> tasks, but when run as a scheduled task it fails.
> I believe it is a problem with the Command Extensions - ie. my batch
> file is using them, and they are not enabled. I get the following
> errors :
>
> 'date /t' is not recognized as an internal or external command,
> operable program or batch file.
> 'time /t' is not recognized as an internal or external command,
> operable program or batch file.


That's right extensions are not enabled. Make sure these reg values are
set to 1

HKEY_USERS\.DEFAULT\Software\Microsoft\Command Processor\EnableExtensions
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\EnableExtensions

If the task was running under a user account (as opposed to the system
account) then logon as that user and check this value:-

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor\EnableExtensions

--
Ritchie, undo for mail


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run batch file from Scheduled Task =?Utf-8?B?Q2hhcmxlcyBMLiBQaGlsbGlwcw==?= Windows XP General 1 8th Dec 2005 07:53 PM
Running a batch file as a scheduled task =?Utf-8?B?SmVmZg==?= Windows XP General 2 18th Nov 2005 12:22 AM
Run Batch File as Scheduled Task =?Utf-8?B?TWlrZSBXaWxraW5zb24=?= Windows XP Security 0 10th Jun 2004 03:49 PM
Batch file not working as a scheduled task David Microsoft Windows 2000 1 8th Oct 2003 12:39 PM
calling a batch file form a scheduled task naftalif Microsoft Windows 2000 CMD Promt 0 11th Sep 2003 08:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:18 PM.