Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
60% | Total: 268 | All time: 7,736 This week: 65 |
Version | License | PHP version | Categories | |||
win-logical-drives 1.0.0 | BSD License | 5.5 | PHP 5, System information, Windows |
Description | Author | |
This package can retrieve the letters of the drives on Windows. Innovation Award
|
<?php
|
The LogicalDrives class is a small utility class that works only on Windows platforms and allows you to query the logical disks that are declared on your system.
It relies on the Windows Management Instrumentation interface (WMI) to retrieve logical drive information.
Documentation about WMI can be found here : https://msdn.microsoft.com/fr-fr/library/aa394582(v=vs.85).aspx.aspx "https://msdn.microsoft.com/fr-fr/library/aa394582(v=vs.85).aspx").
You can also get some information about the kind of data held in a LogicalDrive object here : https://msdn.microsoft.com/en-us/library/aa394173(v=vs.85).aspx.aspx "https://msdn.microsoft.com/en-us/library/aa394173(v=vs.85).aspx") (an object of class LogicalDrive maps directly to the WMI class Win32_LogicalDisk).
Additionally, you will find a more generic WMI access implementation in PHP here : http://www.phpclasses.org/package/10001-PHP-Provides-access-to-Windows-WMI.html
Before retrieving drive information, you need to have an instance of the LogicalDrives class :
include ( 'LogicalDrives.phpclass' ) ;
$ld = new LogicalDrives ( ) ;
The constructor takes no parameter.
You can then call one of the methods implemented by the LogicalDrives class, such as GetAssignedDrives(), which retrieves the list of currently assigned logical drives :
$assigned_drives = $ld -> GetAssignedDrives ( ) ;
the method will return an array of strings containing the drive letters that are currently assigned on your system, followed by a semicolon. You can go further and use them for indexing your LogicalDrives instance and get access to individual drive information, which will be presented as an object of class LogicalDrive ; the following example will display the volume name (or label) for each drive letter that has been assigned to your system :
foreach ( $assigned_drives as $letter )
{
$drive = $ld [ $letter ] ; // You can access a LogicalDrives object as an array
echo "Drive $letter ({$drive -> VolumeName})\n" ;
}
The LogicalDrives class is the main interface to access logical drive information. Since it implements the ArrayAccess interface, it can be accessed using either :
The class also implements the Iterator interface, meaning that you can retrieve individual drive information using foreach() constructs.
The constructor takes no parameter and immediately retrieves information about all the logical disks that are defined on your system.
public function GetAssignedDrives ( )
Returns an array of strings representing the drive letters that are currently assigned on your system.
Drive letters are systematically in uppercase and followed by a semicolon.
public function GetNextAVailableDrive ( )
Returns the next available drive letter.
Drive letters are systematically in uppercase and followed by a semicolon.
public function GetUnassignedDrives ( )
Returns an array of strings representing the drive letters that are currently unassigned on your system (and therefore free for later use).
Drive letters are systematically in uppercase and followed by a semicolon.
The LogicalDrive class encapsulates a Wmi WIN32\_LogicalDisk object for a given logical drive and implements all the properties that can be found in such an object (see https://msdn.microsoft.com/en-us/library/aa394173(v=vs.85).aspx.aspx "https://msdn.microsoft.com/en-us/library/aa394173(v=vs.85).aspx") for more information about this Wmi class, and about all the constants that are defined in the LogicalDrive class).
You will find additional methods and constants that are described below :
public function GetDriveType ( )
Returns the drive type as a string ; it can be any of the following values, depending on the drive :
This method is designed only to provide a human-readable string describing the drive type. To programmatically determine the actual drive type, it is far better to use the DriveType property and compare it against one of the LogicalDrive::DRIVE\_TYPE\_\* constants.
public function GetNetworkName ( ) ;
Returns an associative array containing the following entries :
$status = $drive -> IsCompactDisk ( ) ;
$status = $drive -> IsLocalDisk ( ) ;
$status = $drive -> IsNetworkDrive ( ) ;
$status = $drive -> IsRamDisk ( ) ;
$status = $drive -> IsRemovableDisk ( ) ;
These functions check that the drive has the specified characteristic : compact disk, local to the system, network-mapped, ram disk or removable disk.
public static function NormalizeDriveLetter ( $letter )
This function is mainly used internally, but has been made public in case of... It returns a "normalized" drive letter corresponding to the supplied input.
The return value is always an uppercase letter followed by a semicolon.
The LogicalDrive class implements the ArrayAccess and Iterator interfaces, so that you can use for() or foreach() constructs to loop through the individual properties currently exposed by the underlying WMI object.
All the constants described below are documented here : https://msdn.microsoft.com/en-us/library/aa394173(v=vs.85).aspx.aspx "https://msdn.microsoft.com/en-us/library/aa394173(v=vs.85).aspx")
Files (3) |
File | Role | Description |
---|---|---|
example.php | Example | Example script |
LogicalDrives.phpclass | Class | Class source |
README.md | Doc. | Documentation |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Reuses | Unique User Downloads | Download Rankings | ||||||||||||||||
100% | 1 |
|
|
User Ratings | User Comments (1) | ||||||||||||||||||||||||||||||||||
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.
Other classes that need this package |
Class | Why it is needed | Dependency |
---|---|---|
PHP Wamp Server Installation Manager | dependency | Optional |