|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-09-21 13:47 UTC] e dot vandeoudeweetering at marcanti dot esprit-sg dot
Description:
------------
To enumerate network drives or printer connections, a COM function 'EnumNetworkDrives()' or
'EnumPrinterConnections()'is used.
When I run my script with 'EnumNetworkDrives()' as an example, an exception is thrown. This exception is also thrown when using the function 'EnumPrinterConnections()'.
Reproduce code:
---------------
<?php
$network = new COM("WScript.Network");
$nd = $network -> EnumNetworkDrives();
for($i = 0; $nd -> Count(); $i += 2) {
print $nd -> Item($i) . " " . $nd -> Item($i +1) . "\n";
}
?>
Expected result:
----------------
G: \\%SERVER%\%SHARE%
I: \\%SERVER%\%SHARE%
J: \\%SERVER%\%SHARE%
K: \\%SERVER%\%SHARE%
L: \\%SERVER%\%SHARE%
M: \\%SERVER%\%SHARE%
Actual result:
--------------
G: \\%SERVER%\%SHARE%
I: \\%SERVER%\%SHARE%
J: \\%SERVER%\%SHARE%
K: \\%SERVER%\%SHARE%
L: \\%SERVER%\%SHARE%
M: \\%SERVER%\%SHARE%
PHP Fatal error: Uncaught exception 'com_exception' with message 'Source: Unknown
Description: Unknown' in C:\Scripts\php\drives.php:6
Stack trace:
#0 {main}
thrown in C:\Scripts\php\drives.php on line 6
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 20:00:02 2025 UTC |
Your code looks broken, try this: for($i = 0; $nd -> Count(); $i += 2) { ^ This means, keep going for all eternity, since nothing ever changes the count. You want $i < $nd->Count()