Question : why does this script work when executed as user, but not when executed as system account

Need to deploy script, which gets deployed with system account.

To test, running the attached code and when executed as a user... works fine.  

To further test, running the attached code as SYSTEM account (by running new command prompt via 'at 01:23 /interactive cmd.exe')... does not work.  Results in "The syntax of the command is incorrect".

Found out the %today% variable is what's causing the problem.  However, it's only a problem when running it as the SYSTEM account.  Why is this??
Code Snippet:
1:
2:
3:
4:
@echo off
set today=%date:~-4%%date:~4,2%%date:~7,2%
 
rename C:\test.log %today%_test.log
Open in New Window Select All

Answer : why does this script work when executed as user, but not when executed as system account

I imagine you will find the default system date is set to a different date format.  Try

echo %date%

then you will either have to change the system locale using the "set default" button in regional options (or wherever it is in xp/vista never looked) or change the parts of the %date:~ etc. to be the different parts of the string.  At the moment it takes:

the last 4 chars (year), from 4th char for 2 (month?), then from the 7th char for 2.

I imagine it has no Day component at the beginning so it will end up with a / character in the filename you are making?
Try:
set today=%date:~-4%%date:~0,2%%date:~3,2%

Steve
Random Solutions  
 
programming4us programming4us