Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a vbs script to make backups of MySQL database files using the MySQLDump command. This is working perfectly and creates a new folder for each day's backups (e.g. 20130110).

However, the script is also meant to tidy up by deleting folder older than x days.

When I run the script manually, it works perfectly, but when I setup the script in the Task Scheduler, and set it to "Run whether user is logged on or not" (using the Administrator user account), the task fails. I believe the issue is permissions, but as the folders are created by the task, they should be able to be deleted by the task.

BTW, the vbs script uses the FileSystemObject DeleteFolder command to do the delete...

Any advice would be appreciated!

EDIT It's definatelty the FileSystemObject DeleteFolder command that's the issue. I've tried setting the folder to have Everyone, full permissions, but still no joy...

share|improve this question
setting 'Run whether used logged on or not' and 'Run with highest privileges' should be all you require for the task to run. If the issue does lie with FSO Delete folder then why does it run manually but not as a scheduled task? If the command is the issue, and there's no workaround, would there be any benefit to re-writing the script in Powershell? – kafka Jan 18 '13 at 13:43
'Run whether used logged on or not' and 'Run with highest privileges' are already set... as you say, might need to re-think... – JezB Jan 18 '13 at 13:57
where does the folder live, ie is it local, or a UNC share / mapped network drive? – kafka Jan 18 '13 at 14:10
It's local - C:\MySQL_Backups\20130112\ etc. – JezB Jan 18 '13 at 14:16
up vote 1 down vote accepted

The answer is as follows:

When setting up the Action, rather than set the 'Program/script' to include the path (e.g. "C:\Scripts\Backup.vbs"), you need to set the 'Program/script' as "Backup.vbs" and the 'Start in' as "C:\Scripts\"

The script now works!

Thanks to for the suggestion...

share|improve this answer

What is the command-line of your task? What ist the "Last Run Result" produced by the task? Do any errors or warnings show up in the "History" tab? Do you have UAC enabled, but neglected to check the "Run with highest privileges" option?

Try adding some debugging code to your script to isolate the error. Personally I prefer logging to the eventlog to avoid filesystem permission issues.

Set sh = CreateObject("WScript.Shell")
sh.LogEvent 4, "marker 1"

' your code here

sh.LogEvent 4, "marker 2"

' more of your code here

sh.LogEvent 4, "marker 3"

' ...

This should give you a general idea of which section of your code is the problematic one. Once you located that, you can add more specific debugging code, e.g.:

' some code

On Error Resume Next
' first instruction here
If Err Then ReportError "Error in 1st instruction"
' second instruction here
If Err Then Report Error "Error in 2nd instruction"
' ...
On Error Goto 0

' more code

Sub ReportError(txt)
  CreateObject("WScript.Shell").LogEvent 1, txt & ": " & Err.Description _
    & " (0x" & Hex(Err.Number) & ")"
  WScript.Quit 1
End Sub
share|improve this answer
It's definitely a permissions issue - if I set the folder to allow Everyone full control, it works... – JezB Jan 18 '13 at 12:19
Correction - I can delete files, but not the folders... – JezB Jan 18 '13 at 12:28
Check the permissions of the parent folder (there's a script on my homepage that might be helpful). Also check the actual error message (see 2nd code sample in my answer). – Ansgar Wiechers Jan 18 '13 at 14:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.