Solved

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

Posted on 2009-04-03
5
183 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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