1

I am trying to display all fixed, removable and network drives of my web server.

PHP Version    -> PHP 7.1.4 (cli) ( ZTS MSVC14 (Visual C++ 2015) x64 )
Apache Version -> Apache/2.4.26-dev (Win64)
OS Version     -> Windows 10 Pro x64 [Version 10.0.15063]

PHP Code:

/* Create a new file system object */
$FileSystemObject   =   new COM('Scripting.FileSystemObject');

/* Get system drives */
$Drives =   $FileSystemObject->Drives; 

/* Possible drive types */
$DriveTypes = array("Unknown","Removable","Fixed","Network","CD-ROM","RAM Disk"); 

$SystemDrives = [];

/* Loop through drives */
foreach($Drives as $Drive ){ 

    /* Get current drive options */
    $DriveOptions   =   $FileSystemObject->GetDrive($Drive); 

    /* If drive is removable, fixed or network */
    if (($DriveOptions->DriveType == 1)||($DriveOptions->DriveType == 2)||($DriveOptions->DriveType == 3)){

        $SystemDrives[] =   array(  "DriveType" =>  $DriveTypes[$DriveOptions->DriveType],
                                    "DrivePath" =>  $DriveOptions->Path,
                                    "DriveLabel"=>  $DriveOptions->VolumeName
                                );

    }   

}

/* Show drives */
print_r($SystemDrives);

Response:

    Array
(
    [0] => Array
        (
            [DriveType] => Fixed
            [DrivePath] => C:
            [DriveLabel] => 
        )

)

Apache runs as SYSTEM. Mapped drive has full permissions for SYSTEM. Any ideas on what i am doing wrong? Thanks!

George R.
  • 25
  • 1
  • 7
  • There's no need to call `GetDrive`. In fact, I'm surprised it returns any useful data, as [that function](https://msdn.microsoft.com/en-us/library/1z6e0fk3(v=vs.84).aspx) expects a string drive spec, not a `$Drive` object. All of the info you want is already in `$Drives`. Delete the line `$DriveOptions = $FileSystemObject->GetDrive($Drive);`, and replace all instances of `$DriveOptions` with `$Drive`. – Chris R. Timmons May 07 '17 at 23:04
  • Thanks @ChrisR.Timmons. I modified my code accordingly but the response remains the exact same. – George R. May 08 '17 at 21:28
  • 1
    This might be an Apache issue. Even though Apache is running under the SYSTEM account, their might be other configuration issues. To find out, try running your code under the built-in PHP web server. Run `php -S localhost:8080 -c .\php.ini`. (The `-c` parameter can be omitted if you're using the c:\windows\php.ini file). Then run the page with something like `localhost:8080/index.php` in a browser. When I run your code using the built-in server on Windows 8.1, I can see all of my mapped network drives. – Chris R. Timmons May 09 '17 at 00:55
  • @ChrisR.Timmons it worked with your suggestion! One small change, i used `C:\php\php.ini` instead of `.\php.ini` because initially i received an error about not finding COM class. Thank you very much for your help! And now? Do you have any idea what could be wrong with apache? – George R. May 10 '17 at 06:11
  • It might not be an Apache issue after all. Apparently, [mapped drives aren't globally visible to all Windows user accounts](https://answers.microsoft.com/en-us/windows/forum/windows_7-desktop/how-to-map-network-drives-for-all-users-in-windows/c8ccf50b-333e-4c30-be8e-e4031c7dd069). There's a lengthy discussion [here](http://stackoverflow.com/q/182750/116198) about how to get around that limitation. My personal preference would be to avoid using mapped drives altogether and use [symbolic links](https://superuser.com/q/210824) instead. – Chris R. Timmons May 10 '17 at 19:11

0 Answers0