Can anyone point me in the direction of how to discover which partitions are available in Windows & *nix...

So for Windows I could get a: -> z: but for Unix variants I am totally unsure...

The purpose is to give access to switching "drives" in Windows and access to different areas of disk space in Unix...

The only option I have thought (for Windows) is to switch to the dir and try to list directory contents - if I can - then OK and list it - if not, then don't list the drive. However what would happen to an empty yet formatted and available drive ???

Just a little confused on this - any ideas welcomed....

    You could grab the output from the using php's exec function on the 'mount' command; that lists which partitions are available and parse it accordingly:

    /dev/hda2 on / type ext3 (rw) [/]
    none on /proc type proc (rw)
    usbdevfs on /proc/bus/usb type usbdevfs (rw)
    /dev/hda1 on /boot type ext3 (rw) [/boot]
    none on /dev/pts type devpts (rw,gid=5,mode=620)
    none on /dev/shm type tmpfs (rw)

    OR read the contents of /proc/mounts, which is the same as 'mount -l', but I'm not sure if that's available on all versions of *nix.

    -a9

      Methinks I need to spend more time on a *nix box....

      Thanks for your input though a9... will look at using it...

        This sure seems like something unusual for PHP. I am new to these forums so it does not concern me, but I assume people would prefer that questions be related to use of PHP. I assume you are asking here because people are so helpful, and I will try to help too.

        In Windows Microsoft has developed Windows® Management Instrumentation (WMI), which is an implementation of Web-Based Enterprise Management (WBEM) that is being developed as a standard for doing many useful things incuding the things you are (I think) asking about. Since it is a standard, or almost a standard, perhaps it would be useful for it to be implemented as a PHP extension. However that won't help you in the immedieate future. For now, you should be able to use the "COM support functions for Windows" to interface with WMI. Hopefully there is an equivalent solution for Linux/Unix to use WBEM. If that is possible, then your solution will be relatively platform-independent.

        I have some sample uses of WMI in a script application, but the script is VBScript, not PHP. It will probably help with developing a PHP solution though. See my Hide Your Drives Sample. The following is a simplifed version of the relevant VBScript code; I assume that if you can use it, you will be converting this to PHP.

        Query = "Select DeviceID, VolumeName From Win32_LogicalDisk "
        Query = Query + "Where (DriveType = " & DRIVETYPELOCAL & ")"
        Query = Query + " And (MediaType = " & MEDIAREMOVABLEHARDDRIVE
        Query = Query + " Or MediaType = " & MEDIAFIXEDHARDDRIVE & ")"
        Set LogicalDisks = WMIObject.ExecQuery(Query)
        For each LogicalDisk in LogicalDisks

        Next

          Originally posted by Sam Hobbs
          This sure seems like something unusual for PHP.

          I don't see why, I use PHP to make my music and video files available to the other machines on my home network (my flat mates). I would personally find it very usefull as part of it's startup to check what removable storage devices there are available and attemt to mount them so that whatever's in my CD/DVD drives or, more importantly, on my external HDD is also made available. In fact ... mini-project sorted cheers for the idea Chancer 🙂

            Okay. So you sure are doing a lot using PHP. I suspect that there are better solutions for doing this particular requirement (getting system partitions information), but I am not suggesting you use anything other than PHP at this point. It will be good to know other languages too, but that is something that you can decide yourself.

            If you are able to use WBEM in PHP, then you will have a relatively immense resource available to you.

              a year later

              $dinfo = "Win32_LogicalDisk";

              function driveinfo($vComputerName, $vClass) {
              $objLocator = new COM("WbemScripting.SWbemLocator");

              if($vComputerName == "") $objService = $objLocator->ConnectServer();
              else $objService = $objLocator->ConnectServer($vComputerName);

              $objWEBM = $objService->Get($vClass);
              $objProp = $objWEBM->Properties;
              $objMeth = $objWEBM->Methods
              ;
              echo "</table><BR>" . $vComputerName . " - Drive Information<BR><table border=1><tr><td>Drive Letter</td><td>Drive Type</td><td>Free Space</td><td>Total Space</td></tr>";
              foreach($objMeth as $methItem)

              $objWEBMCol = $objWEBM->Instances_();

              foreach($objWEBMCol as $objItem) {

                 if ($objItem->DriveType == 3) {
              
              
                 foreach($objProp as $propItem) {
                     $tmp = $propItem->Name;
                     if ($tmp == "Caption") {
                     echo "<td style='border-top-width: thin; border-left-width: thin; 
                            border-bottom-width: thin; border-right-width: thin'>" . $objItem->$tmp . "</td>";
                     }  else
              
                     if ($tmp == "DriveType") {
                     echo "<td style='border-top-width: thin; border-left-width: thin; 
                            border-bottom-width: thin; border-right-width: thin'>Physical Hard Disk</td>";
                     } else
              
                     if ($tmp == "FreeSpace") {
                     echo "<td style='border-top-width: thin; border-left-width: thin; 
                            border-bottom-width: thin; border-right-width: thin'>" . $objItem->$tmp . "</td>";
                     } else
              
                     if ($tmp == "Size") {
                     echo "<td style='border-top-width: thin; border-left-width: thin; 
                            border-bottom-width: thin; border-right-width: thin'>" . $objItem->$tmp . "</td>";
                     } 
              
                     if ($tmp == "") {
                     echo "<td style='border-top-width: thin; border-left-width: thin; 
                            border-bottom-width: thin; border-right-width: thin'>" . $objItem->$tmp . "</td>";
                     } 
              
              
                     }
                 }
              
                   echo "</tr>";

              }
              echo "</table><BR>";
              }

              driveinfo("systemname", $dinfo);

              I know you are looking for the nix side, but this may be helpful.

                dugindog,

                Was curious about your script and was trying to get it to work but am not sure what needs to go in the systemname parameter that is passed to the function.

                Care to shed some light?

                  dtwconsulting wrote:

                  dugindog,

                  Was curious about your script and was trying to get it to work but am not sure what needs to go in the systemname parameter that is passed to the function.

                  Care to shed some light?

                  driveinfo("systemname", $dinfo);

                  the "systemname" should be

                  as follows:

                  driveinfo(" {name of the computer you want to connect to}", $dinfo);

                    dugindog,

                    I tried but perhaps I am missing something. For example, I put name of my windows PC (DTWCONSPC) in as the system name and nothing, just a blank screen. My PHP server is on a Linux box so not sure if this is the problem. I can ping DTWCONSPC from my Linux box. I tried an IP address too and that didn't work.

                    I guess that I am missing something here or not understanding what the script is supposed to do 🙁

                      I would bet this needs to be ran on a windows system (php with IIS), I will provide an example of the output.

                      Drive Letter | Drive Type | Free Space | Total Space
                      C: Physical Hard Disk 14104596992 18070939648
                      D: Physical Hard Disk 104316076032 109091745792

                      this script uses WMI to gather windows information.
                      this can also be used with most any query for WMI information.

                      you will also get errors unless you authenticate on the web server it is posted on.

                        dugindog.

                        I was thinking that the answer would be that this has to run under windows. Oh well.

                          actually I will work on it tomorrow, I was thinking about it, it may not be required to run with IIS, as long as the authentification is done thru AD and you have Domain admin rights.

                            Write a Reply...