Problem with exec() and Powershell

Hi there :slightly_smiling_face:

I have a problem running Powershell commands with ExeOutput. I have a script that reads data from the %ProgramData% folder. If it is not in the C: drive, I need to find it. To do this, I need to read which drives are local hard drives (as opposed to any network drives), and I am doing this by using exec() and a Powershell command.

The script runs fine in a browser, but refuses to work from ExeOutput. It just hangs and does nothing. When I close my app, the window closes but the process is still running in the background and does not die.

This is my code:

Any help would be appreciated.

Many thanks,


Might help you along. Use something like below to ID local drives (over network drives) and find Windows dir’s in my software’s built for school use:

// Identify all drives
for ($letter = 'a'; $letter <= 'z'; $letter++) {
    if (is_dir($letter . ':')) {
        echo $letter . ':\\' . PHP_EOL;

// Get path to ProgramData folder
$programDataPath = getenv('ProgramData');

// Check if it is a directory
if (is_dir($programDataPath)) {
    // Open the directory
    if ($handle = opendir($programDataPath)) {
        // Read all items in the directory
        while (false !== ($entry = readdir($handle))) {
            echo $entry . PHP_EOL;

        // Close the directory

Been awhile since looked at actual code in my program, so above is just example. Cannot recall if I had to add the COM extension for PHP or not.

There are some other ways no doubt. Support may be able to recommend better. I do not know about the %ProgramData% folder, but this worked for me on the Public Doc folder, maybe there is something similar for the ProgramData folder:

function GetPublicDocPath: String;
Result := GetSpecialFolderPath(46);

Then you can get the path in PHP thanks to:
$path = exo_return_hescriptcom (‘UserMain.GetPublicDocPath’, ‘’);

1 Like

Heya oldteacher :slightly_smiling_face:

I tried similar code to yours, but it still has the issue of not being able to tell if the drive is local or networked, unless I am missing something ?

I did find a different command that works in CMD rather than Powershell though, which doesn’t hang.

wmic logicaldisk get deviceid, description

which gives

Description         DeviceID
Local Fixed Disk    C:
Local Fixed Disk    D:
Local Fixed Disk    E:
Local Fixed Disk    F:
Network Connection  G:
Network Connection  H:
Network Connection  R:
Network Connection  Z:

Currently waiting for my friend to test, but would still like to know why Powershell won’t work. I can’t seem to find any errors. It just hangs.

I have a look at the 2nd bit in a while.

Many thanks,


Of course. I am not a exeout guru. My recommendation is to forget my code and wait on exeout support. But I will give you one tip:

Posting your code in an image instead of in a code tag would help other to see what you are trying. I personally would never try to enter your code from an image and test it.

I HAD to !! When I tried to paste it, I got an error from the website “403 Forbidden” so something in my code wasn’t allowed. :smile:

LOL, been there on this board, sometimes really picky on code. One thing I have learned is NEVER include php or script tags.

Give support a few days, they may have a much better solution than mine.

1 Like

Now I’ve got time - I’ll try to work out what it was…

Ok - It’s THIS line…



Hi all :slightly_smiling_face:

Just discovered that the method I had found (using WMIC) was depricated in Win 10, in favour of Powershell :disappointed:

This means I really need to get Powershell working, or I might pick up network drives.

Pasting code here can be a challenge.

Have you tried to run your program with administrator privileges? May be required to run powershell.

Now I am kind of looking into the dark, but maybe this will help you:

$fso = new COM('Scripting.FileSystemObject'); 
$D = $fso->Drives; 
$type = array("Unknown","Removable","Fixed","Network","CD-ROM","RAM Disk"); 

foreach($D as $d ){ 
   $dO = $fso->GetDrive($d); 
   $s = ""; 
   if($dO->DriveType == 3){ 
       $n = $dO->Sharename; 
   }else if($dO->IsReady){ 
       $n = $dO->VolumeName; 
       $s = file_size($dO->FreeSpace) . " free of: " . file_size($dO->TotalSize); 
       $n = "[Drive not ready]"; 
   echo "Drive " . $dO->DriveLetter . ": - " . $type[$dO->DriveType] . " - " . $n . " - " . $s . "<br>"; 

function file_size($size) 
    $filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"); 
    return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : '0 Bytes'; 

Only thing to remember is PHP COM extension is required for above code.

Looks like I better start exploring powershell myself :slight_smile:

1 Like

THAT WORKED :slight_smile: (The script that is).

Thanks so much :slight_smile: I can work with that :heart_eyes:

Many thanks,


1 Like

Glad I could help. Have spent many hours over the past 10 years beating my head on desk when working with exeout. Love exeout but can be challenging at times.

1 Like

Now I have another question. What would M 2 drives show as being ? Would they fall under “Fixed” or “RAM Disk” ? (I don’t even have a computer with a slot for one :smile:)

Apparently they would show as “Fixed”.
“RAM Disk” refers to the RAM Disks that first appeared back in Dos 3.0 days and apparently are still supported today !

Definitely fixed. My desktop has one and confirmed it will be shown as fixed:

1 Like

Thanks very much hunny :slight_smile: