4

Server running 2003R2.

I have a script, which basically sets a variable, which then uses it to name a backup file. I have given the exact script here:

echo > "%temp%\tmp.vbs" wscript.echo 10000 * month(now()) ^
+ 100 * day(now()) + year(now())-2000 
for /F %%a in ('cscript //nologo "%temp%\tmp.vbs"') do (
set MyDate = %%a)
echo %MyDate% >test.txt

This script is run from Scheduled Task. When I run the task under my login, and run it as myself, it runs perfectly. However, if I run the task as Domain Administrator, or some other "Backup" user, the set command on the given above does not work.

I have put the last echo command for test purpose.

When it works, it gives me the actual value of MyDate. When not, it just ignores the value, as if it was not even there. I get "Echo is off" command, as if the command was Echo only...

Just cannot understand why it runs under some users, and not under some users.

And insight, and enlightenment would help.

Thanks.

  • Just a thought... it might be an issue with regional settings and date formatting. What is the system language? Maybe the regional settings are different for your user and for the domain admin? – Massimo Dec 19 '14 at 12:33
  • How does `echo MyDate >test.txt` work? Wouldn't you need the enclosing `%`s? With my current regional settings I can just do `ECHO %date:~4,2%%date:~7,2%%date:~12,2%` without shelling out to cscript. – jscott Dec 19 '14 at 12:47
  • There has been no change in the settings and date, both are the same. – Manoj Duwady Dec 20 '14 at 13:08
  • I used that echo line jst to test different variables. Yes, echo %MyDate% is the correct way for getting the value of Mydate. I was just playing around to see what works, what does not... I have tried both, and tried echoing more variables from the script, to find out where the problem is. – Manoj Duwady Dec 20 '14 at 13:10

1 Answers1

1

You will need to enter the 'Properties' menu of the scheduled task you have created, and in the 'Security options' box on the 'General' tab, select the 'Run whether user is logged on or not' (which will then require that you input the user's password when clicking 'OK' to close the Properties window).

Depending on your permissions etc, you may also need to select 'Run with highest priveleges'.

You can manually try running the scheduled task by right-clicking it and selecting 'run', then refreshing the page to display the 'Last Run Result' - then checking the code against the MS table of system error codes to assist in the diagnosis of what went wrong.

BE77Y
  • 2,667
  • 3
  • 18
  • 23
  • I did go to properties of scheduled task, and ran it with "run-as" feature for both my login (I am administrators group) as well as domain administrator login. It runs under my login, but not under Domain admin's login. I ran it with highest privileges. The last run code that I get is 0x80. – Manoj Duwady Dec 20 '14 at 13:07
  • I don't understand, does the script run an you get an empty txt file or do you get an error on the sched tassk? – EliadTech Dec 21 '14 at 12:15
  • In the scheduled task, did you also explicitly set a directory for the script to run from and/or made sure that all necessary users have write permissions to that directory? – rubynorails Sep 27 '15 at 02:55