Hello All!
I am writing VBScript to determine how many hard drives I have on the
local machine and do a disk defrag(Or just analyze) based on the
result return to me. I wanna do it automatically. Now I could start
disk management console and disk defragmentation console when i run
the scrip. I use winshell object and run method. That's kind of easy,
but this still need some manual configuration. Anyone knows how to
achieve my original goals?

Thanks!

Sincerely,
Ben

Re: How could I get hard drive information? by OldDog

OldDog
Wed Apr 04 18:58:24 CDT 2007

On Apr 4, 4:16 pm, "Benny Van" <fyf5555...@gmail.com> wrote:
> Hello All!
> I am writing VBScript to determine how many hard drives I have on the
> local machine and do a disk defrag(Or just analyze) based on the
> result return to me. I wanna do it automatically. Now I could start
> disk management console and disk defragmentation console when i run
> the scrip. I use winshell object and run method. That's kind of easy,
> but this still need some manual configuration. Anyone knows how to
> achieve my original goals?
>
> Thanks!
>
> Sincerely,
> Ben

Give this a try;

<---------------------------------------
VBScript-------------------------------------------->

'Initialization Section

'Option Explicit
Dim objWshShl, DiskSet, Disk

strComputer = "."

Set objSWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objSWbemLocator.ConnectServer(strComputer, _
"root\CIMV2", _
strUser, _
strPassword, _
"MS_409", _
"NTLMDomain:" + strDomain)

Set objWshShl = WScript.CreateObject("WScript.Shell")


'Main Processing Section

Set dskItems = objWMIService.ExecQuery("SELECT * FROM
Win32_LogicalDisk where DriveType=3")
For Each oItem In dskItems

dName = oItem.Name

RunDefragUtility()

RecordMsgToAppEventLog()


Next


'Procedure Section


Function RunDefragUtility() 'Run the defrag.exe command-line utility


Wscript.Echo dName

objWshShl.Run "c:\Windows\System32\defrag " & dName & " /f"

End Function


<-------------------------------end
script------------------------------------------------->