Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-04-03
5
Medium Priority
?
187 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:JAM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 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:JAM
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:JAM
ID: 24062500
wait, I may have had a typo, reviewing now and will post back revised results...
0
 
LVL 1

Author Comment

by:JAM
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

610 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