Solved

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

Posted on 2009-04-03
5
180 Views
Last Modified: 2012-05-06
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??
@echo off

set today=%date:~-4%%date:~4,2%%date:~7,2%
 

rename C:\test.log %today%_test.log

Open in new window

0
Comment
Question by:jam21000
  • 3
  • 2
5 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 24062223
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
0
 
LVL 1

Author Comment

by:jam21000
ID: 24062466
dragon-it:

when, in the SYSTEM cmd prompt, I run

echo %date%

I get --> Fri 04/03/2009


Tried

set today=%date:~-4%%date:~0,2%%date:~3,2%
rename C:\test.log %today%_test.log

and although that (also) worked running as regular user, I got the same problem when running it as SYSTEM... ??
0
 
LVL 1

Author Comment

by:jam21000
ID: 24062500
wait, I may have had a typo, reviewing now and will post back revised results...
0
 
LVL 1

Author Comment

by:jam21000
ID: 24062664
yep, I had a typo... your solution worked like a charm, thanks!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 24063264
Glad it helped... not sure how if the system cmd.exe returned date with DDD dd/mm/yyyy etc. but heh as long as it works for you!

Steve
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now