Author Topic: Running a windows batch file via windows task scheduler to backup files  (Read 3064 times)

ThomU

  • Calf
  • *
  • Posts: 2
G'day,

I'm attempting to run a simple dos batch file to copy files from the linkstation to a local hard drive for backup purposes.  When I'm logged into the windows workstation and run the batch file, all works correctly.  But when I attempt to run the batch file via a windows task scheduler task, it fails with an error result of 0x4, which is permission related.  I'm running the task under the same user account that I'm able to run just fine as a user.  Anyone have any suggestions?  Thank you!

Kane88

  • Buffalo
  • ***
  • Posts: 161
Re: Running a windows batch file via windows task scheduler to backup files
« Reply #1 on: January 24, 2020, 01:36:29 PM »
Scheduled tasks run from the system account. 
Part of it may also depend on what you're entering for the command.

see here:
https://superuser.com/questions/425700/why-does-my-scheduled-task-fail-with-error-0x4

1000001101000

  • Debian Wizard
  • Big Bull
  • *****
  • Posts: 1128
  • There's no problem so bad you cannot make it worse
Re: Running a windows batch file via windows task scheduler to backup files
« Reply #2 on: January 24, 2020, 02:07:55 PM »
Quote
Scheduled tasks run from the system account.
Part of it may also depend on what you're entering for the command.

see here:
https://superuser.com/questions/425700/why-does-my-scheduled-task-fail-with-error-0x4

I believe you're mainly right. At least that the lack of user context and/or access to stored credentials being what is preventing this from working. However schedules tasks in windows can be configured to run as SYSTEM or as a particular user. You can likely make this work by adjusting your task to run under your user profile.

It's been a few years since I've done this, and it was in an Active Directory environment at the time. There are several options regarding how that session operates, I believe one of them should make this possible.

ThomU

  • Calf
  • *
  • Posts: 2
Re: Running a windows batch file via windows task scheduler to backup files
« Reply #3 on: January 24, 2020, 08:06:04 PM »
Thank you for the replies.  I'm running the task in task scheduler using the same account credentials that I'm able to run the batch file successfully manually.  Any other suggestions?

Kane88

  • Buffalo
  • ***
  • Posts: 161
Re: Running a windows batch file via windows task scheduler to backup files
« Reply #4 on: January 24, 2020, 08:39:31 PM »
Quote
Scheduled tasks run from the system account.
Part of it may also depend on what you're entering for the command.

see here:
https://superuser.com/questions/425700/why-does-my-scheduled-task-fail-with-error-0x4

I believe you're mainly right. At least that the lack of user context and/or access to stored credentials being what is preventing this from working. However schedules tasks in windows can be configured to run as SYSTEM or as a particular user. You can likely make this work by adjusting your task to run under your user profile.

It's been a few years since I've done this, and it was in an Active Directory environment at the time. There are several options regarding how that session operates, I believe one of them should make this possible.


True- the tasks can be assigned to specific users.  I was just saying that by default- they run from the system account.
Unless there's some GPO that prevents the user from running tasks.  We need more info either way.

Kane88

  • Buffalo
  • ***
  • Posts: 161
Re: Running a windows batch file via windows task scheduler to backup files
« Reply #5 on: January 24, 2020, 08:41:21 PM »
Thank you for the replies.  I'm running the task in task scheduler using the same account credentials that I'm able to run the batch file successfully manually.  Any other suggestions?
I think we need more info at this point.
What are you trying to run?  And how?

It sounds like a permissions problem to me- depending on where the script is stored, and what you're trying to do (edit:syntax), and also- what you've got the settings as.
If this is a domain pc- there may be a GPO that is preventing the task from being ran. (Edit:Group policy can even block administrators from running scripts on their own pc's- that's what domain control from top level- is all about)
Or you've got some setting that needs adjusting on the task itself.
By default, the tasks will run from the system account.

Is it executing at all, even if you force it?
Does it give you an error?  What does the event log say?
Is it set for run whether user is logged in or not?
Is the task enabled?

Check conditions tab.  Make sure it's set appropriately for laptop/ac power.

With my scheduled tasks, I generally just have it run a .bat file I've already made.

If it's something on a server itself- best to run with a (Edit: a domain) service account that has the needed permissions.

(Edit: Take a look at your script- and also check what groups your account belong to as well as the computer account- if on a domain.
Windows has its own caveats- but even domain controllers have authority over local policy- GPOS - they do block even admins- from running their own scheduled scripts locally... their computers have to be in the right OU and have their own appropriate- GPO, in that respect Windows is actually- fairly secure.)

« Last Edit: January 25, 2020, 01:48:47 AM by Kane88 »