Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to run defrag as a service

Status
Not open for further replies.

sapper1

Technical User
Jul 13, 2006
99
0
0
US
We have several servers running server 03 enterprise. I would like to setup defrag to run on a schedule on each of the servers. I know how to do this using Scheduled tasks but I would like to know if there is a way to have defrag run as a service as I think it would be easier to manage. For example, when I setup defrag through Scheduled tasks I have to supply a user name and password. If that password changes then I have 50+ servers to change that on. If I can have defrag run as a service I would hope that this problem would be avoided. Any thoughts are greatly appreciated.
 
You're almost better off running something like Diskeeper, O & O Defrag or Raxco Perfect Disk than try to get Windows to run to run defrag as a service.

I don't think it can anyway. In Win 2008 & Vista it will run as a service but I don't think it will in previous versions. I'd be curious to see if anyone got it to run as a service but I wouldn't hold my breath on it.

The answer is always "PEBKAC!
 
I have used psexec from the pstools resouce kit to run this from a central location referencing a text file for server names. Now the file will need updating when u add new servers, but it is a simple way to automate Windows Defrag. Just point the psexec at the C:\windows\system32\defrag.exe
 
start c:\psexec \\"servername" -s c:\windows\system32\defrag.exe c: /f


figured i would save you some time.
 
You're all overcomplicating this...

Use the Windows "AT" command to set up a scheduled task. This task launches a simple batch file, that runs a simple VBScript that launches the Windows disk defragmenter.

All simple... all free.... and all runs under local system privileges... no domain user accounts involved.

Contents of the batch file> C:\defrag.vbs
(this assumes that the location of your VBScript will be on the root of C, but the VBScript can be stored anywhere)

Contents of the VBScript file (in this case we're calling it defrag.vbs) >

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colVolumes = objWMIService.ExecQuery _
("Select * from Win32_Volume Where Name = 'C:\\'")

For Each objVolume in colVolumes
errResult = objVolume.Defrag()
Next


......if you have multiple drives, C, D and E etc. you'll need to set up a scheduled task and script for each. You can create the batch file and the VBScript file in notepad. For the VBScript file, save the notepad file with a .vbs extension instead of the normal .txt and for the batch file, save the file with a .bat extension.

For info. on the AT command >
 
Agree with ArizonaGeek...
For $100.00 you can get Perfect Disk, which is a great deal more powerful than the OS defrag, and most importantly will do a boot time defrag, setup is very simple. I do a boot time every few months, normal defrag nightly. A boot time defrag is important as resident programs/OS do not get defragmented by the OS version; Eg. SQL will increase speed about 5-7% with a boot time defrag over a normal defrag. Normally I use Diskeeper, but at $ 299.00, it is now over priced.

........................................
Chernobyl disaster..a must see pictorial
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top