Setting up a defrag scheduled task via Group Policy

Posted on 2009-04-27
Last Modified: 2013-11-25
I am trying to figure out how to set up a scheduled defrag task with Group Policy.
I am very new to this, and I am having a great deal of difficulty determining the proper way to do this. I have looked through the knowledge base, but I have not been successful in getting anything to work properly. Im sure it is due to my lack of experience in this area.

The users I have created in AD log on to our Domain, and are placed in the local users group on the PC by default. It appears that I may be having a permission problem when I run the following bat file:

schtasks.exe /create /SC WEEKLY /D Mon /TN defrag /TR "\"C:\windows\system32\defrag.exe\"c: -f" /ST 10:35:00 /SD 04/27/2009 /RU SYSTEM

The scheduled task never gets created via the log on script when the user is in the local users group on the PC.

If I put the word pause at the end of the bat file I get the following error:

C:\>schtasks.exe /create /SC WEEKLY /D Mon /TN defrag /TR "\"C:\windows\system32
\defrag.exe\"c: -f" /ST 10:35:00 /SD 04/27/2009 /RU SYSTEM
INFO: The Schedule Task "defrag" will be created under user name ("NT AUTHORITY\
ERROR: Access is denied.

Press any key to continue . . .

If I move the user to the local admin group, the task gets created and runs with no problems. I am trying not to resort to this to solve this problem.

Should I be looking at a startup/shutdown script instead? If so what considerations do I need to take for computer accounts?

Thank you in advance,

Question by:dwesolowicz
    LVL 30

    Accepted Solution

    If you have deployed Group Policy Preferences (GPP), you can deploy this without the use of login scripts:

    Deploying GPP requires you to administer Group Policies from a Vista or 2K8 computer, and requires you to deploy the GPP Client-Side Extensions to your XP/2K3 machines. Deploying GPP does -not- require 2008 Active Directory.

    Author Comment

    Sorry for the delay and thank you for the reply.

    After doing further research, it appears that you can not run a scheduled task if you are not a local admin on the PC. I also found PsTools at Sysinternals. Within the tools you can run a command called psexec.exe.

    This gives you the capability to run defrag via command line on several computers simultaneously.
    Since I am a domain admin and running the process from my laptop, I am able to kick off a defrag without getting "access denied".

    Thanks again


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    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

    Cobalt Digital Marketing began using the Scrum Framework development process in summer 2009.  We hired a consultant to train the teams, observe meetings, and answer questions. He recommended that we begin using one-week sprints for several reason…
    Agile and Scrum have almost become synonymous. Have you wondered what's the difference? Scrum is just one way to be Agile. It is the most popular which leads to the common confusion. Agile actually refers to a philosophy shared by group of developme…
    This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

    779 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