Working with Hard Disks

When you are creating a custom application, you may want to get information about hard disks that are on the home server. By using the API for Windows Home Server, you can write code that retrieves information about hard disks that are on the home server.

Hard Disk Properties

An individual hard disk is represented as a IDiskInfo object, and it has read-only properties for the following attributes:

  • Size

  • Device path

Hard Disk Example

Step 1: Create an instance of WHSInfoClass

As with most API objects for Windows Home Server, retrieving information about hard disks begins by creating an instance of the WHSInfoClass, as follows:

WHSInfoClass pInfo = new WHSInfoClass();
Dim pInfo As New WHSInfoClass()

Step 2: Call the GetDiskInfo() method

The GetDiskInfo method is the WHSInfoClass method that you use to get information about hard disks that are on the home server. It returns an array of IDiskInfo objects that represent all hard disks on the server:

Array disks = pInfo.GetDiskInfo();
Dim disks As Array = pInfo.GetDiskInfo()

Step 3: Loop through the array

Because the GetDiskInfo method returns only an array of IDiskInfo objects, you need to loop through the entire array to get information about a particular instance of a hard disk:

foreach (IDiskInfo pDisk in disks) 
{
  Console.WriteLine("Size: {0}" + pDisk.Size);
  Console.WriteLine("Device Path: {0}" + pDisk.DevicePath);
}
Dim pDisk As IDiskInfo
For Each pDisk In disks
    Console.WriteLine("Size: {0}" + pDisk.Size)
    Console.WriteLine("Device Path: {0}" + pDisk.DevicePath)
Next pDisk

You can use this same approach whenever you need to work with hard disks through the API for Windows Home Server.

See Also

Reference

IDiskInfo
WHSInfoClass

Concepts

Extending Windows Home Server
Working with WHSInfoClass
Working with Client Computers
Working with Users
Working with Application Folders
Working with Managed Volumes
Working with Notifications
Working with Backups

Other Resources

Working with Shared Folders