Solved

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

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershellscript,save output as .txt file in the same dir 9 79
Vbscript 8 97
Batch/VBScript : Disable Windows tasks 7 45
Batch file to convert a xlsx file to csv 5 238
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…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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