Solved

Trying to find a solution to defrag all workstations on our domain on a schedule after hours

Posted on 2008-10-16
9
474 Views
Last Modified: 2012-05-05
I have been trying to  many different vbscripts and.bat files that are set up to run a chkdsk and defrag all workstations on our domain. I have placed them in \\Domain\netlogon and created a group policy and then added the script to run on start up. I have been unable to get this to execute on any workstation.

I dont' have any problem placing a script on each workstation and running it through scheduled tasks. The problem that I run into there is that defrag will not run unless is an administrator account.

I'm looking for a solution to any of these problems and my last resort is to use a third party defrag application that would run without admin rights.
0
Comment
Question by:hcp27
  • 5
  • 3
9 Comments
 
LVL 66

Expert Comment

by:johnb6767
ID: 22733170
Perform volume maintenance tasks
http://technet.microsoft.com/en-us/library/cc779312.aspx
Dont think this works on the CLI version of Defrag.exe, but the GUI should work...
0
 

Author Comment

by:hcp27
ID: 22733476
I added every user to be able to Perform volume maintenance tasks in the appropriate Group poicy object editor. I tried to run the script on a workstation without admin rights and it still says cannon start task.

I also tried to start defrag manually though system tools and it's still give me the You must have administrator privileges to defragment a volume.
0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 22733509
Set the scheduled tasks to run under the user NT AUTHORITY\SYSTEM.  Leave the password blank.  They will then run with administrative rights.

You can script this change in a batch script like the one below.  It gets the target computer names from a file named computerlist.txt and the name of the scheduled task to edit is set with the /TN switch.


@echo off
 

for /F %%G in (computerlist.txt) do schtasks /change /S %%G /RU "NT AUTHORITY\SYSTEM" /TN "defragtask"

Open in new window

0
 

Author Comment

by:hcp27
ID: 22733564
Here is the script i'm trying to run. How would you change this?
'Program: CheckAndDefrag.bat

'Author: Pat Lee

'Date: 6/12/2008

 

'Clear all scheduled tasks defined by this script

schtasks /delete /tn "DirtyBit Task" /f

schtasks /delete /tn "Restart Task" /f

schtasks /delete /tn "Defrag Task" /f

 

'Set scheduled tasks to set chkdsk, restart and defrag

schtasks /create /ru "SYSTEM" /sc WEEKLY /d SUN /TN "DirtyBit Task" /tr "c:\windows\system32\fsutil.exe dirty set c:" /st 00:45:00 /sd "01/01/2008"

schtasks /create /ru "SYSTEM" /sc WEEKLY /d SUN /TN "Restart Task" /tr "c:\windows\system32\shutdown.exe -r -t 60" /st 01:00:00 /sd "01/01/2008"

schtasks /create /ru "SYSTEM" /sc WEEKLY /d SUN /TN "Defrag Task" /tr "c:\windows\system32\defrag.exe c:" /st 02:00:00 /sd "01/01/2008"

Open in new window

0
Do email signature updates give you a headache?

Are you constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

 

Author Comment

by:hcp27
ID: 22733655

At this point I'm willing to just use this script that only executes Defrag.exe
set WshShell = CreateObject("WScript.Shell")
 

'Launch Defrag from the command line and wait for a second

WshShell.Run "dfrg.msc"

WScript.Sleep 1000
 

'Wait until the application has loaded - Check every second

While WshShell.AppActivate("Disk Defragmenter") = FALSE

     wscript.sleep 1000

Wend
 

'Bring the application to the foreground

WshShell.AppActivate "Disk Defragmenter"

WScript.Sleep 200
 

'Send an ALT-A key to bring down the degrag menu

WshShell.SendKeys "%A"

WScript.Sleep 200
 

'Send a D to start the defrag

WshShell.SendKeys "D"
 

'Wait until the defrag is completed - Check for window every 5 seconds

While WshShell.AppActivate("Defragmentation Complete") = FALSE

     wscript.sleep 5000

Wend
 

'Bring the msgbox to the foreground

WshShell.AppActivate "Defragmentation Complete"

WScript.Sleep 200
 

'Send a tab key to move the focus from View Report button to the Close Button

WshShell.Sendkeys "{TAB}"

Wscript.Sleep 500
 

'Send key to Close the Defragmentation Complete window

WshShell.Sendkeys "{ENTER}"

Wscript.Sleep 500
 

'Send and ALT-F4 to Close the Defrag program

WshShell.Sendkeys "%{F4}"

Open in new window

0
 
LVL 38

Expert Comment

by:Shift-3
ID: 22733924
That first script looks fine to me.
0
 

Author Comment

by:hcp27
ID: 22734267
I set the run as NT AUTHORITY\SYSTEM and then logged into an account that doesnt have the admin rights. It I executed the script and it at least doesn't say that it couldnt start. Will this defrag utility pop up like defrag.exe and show the progress of the defragmentation? I know the restart works cause it will pop up saying that the system is being shutdown by NT AUTHORITY/SYSTEM.
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 22735313
No, the task will not run interactively.  You can see if it is running by checking the Processes tab in Task Manager or looking under the Status column in the Scheduled Tasks window.
0
 

Author Closing Comment

by:hcp27
ID: 31506820
Thank you so much for your help. I have been trying to figure this out for a week now and I'm not to familiar with this. Really appreciate everything.

Thanks again
0

Featured Post

Swamped with email signature updates?

Have you been given a load of changes to make to your users’ email signatures? Having to manually implement multiple signatures for every department? Let Exclaimer save you from being swamped with email signature updates!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sccm report 1 38
pdf convertor 7 64
error windows 7 restart automatically 9 37
MsgBox 4 43
This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
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…

929 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

11 Experts available now in Live!

Get 1:1 Help Now