Solved

windows 7 task schedule

Posted on 2014-12-31
7
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Windows running painfully slow? Try these tips..

Stay away from Speed Up Computer Programs that do more harm than good.
Try these tips instead.
Step by step instructions in trouble shooting Windows Performance issues.

 
LVL 84

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 84

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
Suggested Courses

738 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