I got this script from the Microsoft Script Center
----------------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")

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

For Each objVolume in colVolumes
errResult = objVolume.Defrag()
Next
------------------------------------------
However when I try to run the script I get the error:

Line: 8
Char: 1
Error: 0x80041010
Code: 80041010
Source: Null

Any Ideas about getting this script to run? What I'm tring to do is
create a .hta that will defrag the hard-drive (and other things).

Re: Script to defrag hard-drives by Walter

Walter
Tue Jun 13 17:54:51 CDT 2006

The Defrag method only works with Windows Server 2003.
http://www.microsoft.com/technet/scriptcenter/topics/win2003/defrag.mspx#EAB

<Cryptographic_ICE@yahoo.com> wrote in message
news:1150235290.821295.309550@i40g2000cwc.googlegroups.com...
>I got this script from the Microsoft Script Center
> ----------------------------------------
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer &
> "\root\cimv2")
>
> Set colVolumes = objWMIService.ExecQuery _
> ("Select * from Win32_Volume Where Name = 'D:\\'")
>
> For Each objVolume in colVolumes
> errResult = objVolume.Defrag()
> Next
> ------------------------------------------
> However when I try to run the script I get the error:
>
> Line: 8
> Char: 1
> Error: 0x80041010
> Code: 80041010
> Source: Null
>
> Any Ideas about getting this script to run? What I'm tring to do is
> create a .hta that will defrag the hard-drive (and other things).
>