Solved

windows 7 task schedule

Posted on 2014-12-31
7
156 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 23

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 23

Assisted Solution

by:NVIT
NVIT earned 250 total points
ID: 40526098
Also, set "Run with highest privileges"
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

First some basics on Windows 7 Backup.  It has 2 components one is a file based backup which is stored in .zip files each zip is split at around 200 Megabytes and there is the Image Backup which is as the name implies a total image of the partition …
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…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now