WMI to get Total Size

G

Guest

When I run the script below I get a "Disk not ready"

What am I doing wrong?

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives

For Each objDrive in colDrives

Wscript.Echo "Total size: " & objDrive.TotalSize

Next

C:\>cscript hd.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\hd.vbs(6, 2) Microsoft VBScript runtime error: Disk not ready
 
B

Bill Blanton

John said:
When I run the script below I get a "Disk not ready"

What am I doing wrong?

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives

For Each objDrive in colDrives

Wscript.Echo "Total size: " & objDrive.TotalSize

Next


From an MSDN? page that I can't find right now-

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("SELECT * FROM Win32_LogicalDisk")

For each objDisk in colDisks
Wscript.Echo "Compressed: " & objDisk.Compressed
Wscript.Echo "Description: " & objDisk.Description
Wscript.Echo "Device ID: " & objDisk.DeviceID
Wscript.Echo "Drive Type: " & objDisk.DriveType
Wscript.Echo "FileSystem: " & objDisk.FileSystem
Wscript.Echo "FreeSpace: " & objDisk.FreeSpace
Wscript.Echo "MediaType: " & objDisk.MediaType
Wscript.Echo "Name: " & objDisk.Name
Wscript.Echo "Size: " & objDisk.Size
Wscript.Echo "SupportsFileBasedCompression: " & _
objDisk.SupportsFileBasedCompression
Wscript.Echo "SystemName: " & objDisk.SystemName
Wscript.Echo "VolumeName: " & objDisk.VolumeName
Wscript.Echo "VolumeSerialNumber: " & _
objDisk.VolumeSerialNumber
Next

You'd also be better off posting scripting questions to a scripting related group.
 
R

Ramesh, MS-MVP

John,

Try the WMI script which Bill posted. Or, use the modified WSH script below
(Echoes the free space info for fixed drives only)

-----------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives

For Each objDrive in colDrives
If objDrive.DriveType = 2 Then
WScript.Echo "Total size: " & int (objDrive.TotalSize / 1048576) & " MB"
End If
Next
-----------------

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


When I run the script below I get a "Disk not ready"

What am I doing wrong?

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives

For Each objDrive in colDrives

Wscript.Echo "Total size: " & objDrive.TotalSize

Next

C:\>cscript hd.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\hd.vbs(6, 2) Microsoft VBScript runtime error: Disk not ready
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top