Online-Admin.com |
 |
Menu |
 |
 |
Quick search |
 |
 |
New version notify |
 |
|
 |
TWmiStorageInfo component |
 |
|
TWmiStorageInfo is a part of
WmiSet Component Collection for Delphi, C++Builder.
This VCL component reports a large variety of information about the storage
devices connected to the local or network computers. The supported
devices include disk drives, floppy drives, CDROMs, tapes. The component
also returns the information about partitions and logical disks.
Download the help file to
see the complete list of component's properties and methods.
|
|
Code sample
|
This Delphi code sample shows how to
- connect to remote computer;
- iterate through the list of remote computer's logical disks
- filter only fixed drives (ignore mapped network drives, CDROMs etc)
- check the space available on the fixed drives.
The procedure expects the tree parameters.
- IPAdress may be address in the form "xxx.xxx.xxx.xxx", for
example "169.254.112.1", or NETBIOS name of the computer.
- UserName should ne in the form "DOMAIN\Name". If this user
name is local to the destination computer (not a domain name), then
specify "COMPUTERNAME\name".
- Password is the password for the account used.
procedure CheckSpace(IPAdress, UserName, Password: string);
const
ERR_MESSAGE = 'Drive %s has only %d bytes of free space';
var
i: integer;
vStorageInfo: TWmiStorageInfo;
begin
// create the component on the fly.
vStorageInfo := TWmiStorageInfo.Create(nil);
try
with vStorageInfo do
begin
// connect to remote computer
// When working with a local machine, all the
// parameters must be empty strings
MachineName := IPAdress;
Credentials.UserName := UserName;
Credentials.Password := Password;
Active := true;
// Iterate through the logical disks
for i := 0 to LogicalDisks.Count - 1 do
begin
// Ignore mapped network drives;
// Find disks with less than 10Mb free space.
if (LogicalDisks[i].MediaType = MT_FIXED) and
(LogicalDisks[i].FreeSpace < 10000000) then
ShowMessage(Format(ERR_MESSAGE,
[LogicalDisks[i].Caption,
LogicalDisks[i].FreeSpace]));
end;
end;
finally
// Clean up.
vStorageInfo.Free;
end;
end;
|
|
Demo program.
|
This demo program is written using TWmiStorageInfo
component. It is implemented as a storage device viewer
that is capable of monitoring devices on a local or remote
computer.
Download WmiSet to
see the source code of the demo application. You may also
download executable here.
|
|