Solved

windows 7 task schedule

Posted on 2014-12-31
7
160 Views
Last Modified: 2015-01-02
Is there a trick to getting win7 to schedule AND run a task? I created a simply Batch file that I would like to run each night at around 10pm. To test, I setup a task in the task scheduler, and have it set to run daily at about 5 mintes from when I created the task. It complained that I need to be a part of the batch job rights group. So I opened secpol.msc, went to Local Policies, User Rights Assignment, and added my account to "Log on as a batch job".
Now it doesn't complain when I schedule the task, and even looks like it runs because I go to the properties of the task, and look at the history tab
It just has a lot information events, one of them, in the task category column has, "Task Started". Then above that, "Action started" and in the general tab it has "task scheduler launched action "C:\test\test.bat" in instance ... which is my test batch file. I know it doesn't work because this batch just copies a file from one local location to a network share, but the file isn't there when I look in the folder on the share.
I know the batch file works because I run it manually and it works fine.
So, any ideas what I am missing.
0
Comment
Question by:JeffBeall
  • 3
  • 2
  • 2
7 Comments
 
LVL 24

Expert Comment

by:NVIT
ID: 40525971
Not sure if this help but... for the task, under General, Security Options, what user account is set? That account should have rights to the target folder.
Also, what Run... button is set?
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 40526090
under general, security options my user account is used

the "Run whether user is logged on or not" is checked, and the "Do not store password" box is not checked
0
 
LVL 24

Assisted Solution

by:NVIT
NVIT earned 250 total points
ID: 40526098
Also, set "Run with highest privileges"
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 83

Expert Comment

by:oBdA
ID: 40526687
Please post your script. It's probably copying a file from C:\test, using something like "copy test.txt \\server\share\folder".
This works when you double-click the script, because the working directory will be set to the script's folder, but when a script is started using the task scheduler, the working directory will be "%Systemroot%\system32", not the script's folder.
To test, simply open a command prompt, enter "cd /d %%Systemroot%\system32%", then run your script from this prompt as C:\test\test.bat. If it errors out, the working directory is the issue.
To reference the script's folder, independently of the working directory, use %~dp0; note that this already has a trailing backslash at the end.
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 40528127
oBdA, I tried doing what you suggested

"To test, simply open a command prompt, enter "cd /d %%Systemroot%\system32%", then run your script"

and the script ran fine. So I thought I would put my batch in C:\windows\system32 because, like you said

" when a script is started using the task scheduler, the working directory will be "%Systemroot%\system32"

but that didn't work either.

I opened the task scheduler as admin and scheduled the batch as admin, wondering if it's a permissions thing, but that didn't work either. Also, in the task scheduler, if I click on the task and choose run, nothing happens
By the way, the batch looks like this.

taskkill /IM OUTLOOK.EXE
choice /N /d y /t 5
robocopy "C:\outlook" "H:\test" /is /FFT /XO /E /PURGE
pause

if I manually run this by double clicking on the batch file, it works every time.
Any ideas?
0
 
LVL 83

Accepted Solution

by:
oBdA earned 250 total points
ID: 40528142
Replace "H:\test" with the UNC ("\\server\share\test"), and remove the "pause"; when run as a task, nobody will be able to press a key.
0
 
LVL 1

Author Closing Comment

by:JeffBeall
ID: 40528438
ok, my batch looks like this now

taskkill /IM OUTLOOK.EXE
choice /N /d y /t 5
robocopy "C:\outlook" "\\DFS001\D01BEAJE02\test" /is /FFT /XO /E /PURGE
pause

I kept the pause to see if it runs ok, once this works, I will remove it.
And it looks like it is working! I think I had to open the task manager as my own account, not the admin, however, before I changed the script per your instructions to the UNC it didn't work if I ran the task manager with my account, or the admin account.

Thank you for the help!
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
On some Windows 7 (SP1) computers, Windows Update becomes super slow even the computer is reasonably fast.  There's one solution that seemed to have worked well for me (after trying a few other suggested solutions).
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

832 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