List of Logical Drives

Solution Available
Michael C.
El Segundo, CA

Oct 18, 2017
7 Posts

1  |  0  

Re: List of Logical Drives


Developing on ATEasy 8.0 on a WinXP Machine.

Attempting to get a list of attached drives via mscorlib's System IO DriveInfo GetDrives() didn't pan out.  It returns an array of DriveInfo.  From previous questions on this forum, I was told returns of arrays are not supported in ATEasy?

I moved on to using Win32_LogicalDisk query via WMI but cannot iterate through the returned SWbemObjectSet.  The only thing I can access is the .Count property.

obCimv2, obCollItems,obItem all declared as objects
iTemp = Long

obCimv2 = GetObject("winmgmts:\\\\.\\root\\cimv2")
obCollItems = obCimv2.ExecQuery("SELECT * FROM Win32_LogicalDisk")
iTemp = obCollItems.Count
obItem = obCollItems.Item(0)    <---- Errors out, needs a strObjectPath, cannot iterate through.  Looking at MSDN example it just uses for each.  
                                                                       ItemIndex doesn't work either

Is there anyway to make GetDrives or the WMI query work?  Or a different method?


Michael C.
El Segundo, CA

Oct 20, 2017
7 Posts

0  |  0  

Re: List of Logical Drives

I found a couple convoluted way to do this:

1.) Used winexec call to call cmd.exe to call WMIC and then pipe it to a temp.txt file.  Then I use ATEasy's fileopen and fileread to read the file back to get the list of drives.

Something like

winexec("cmd.exe /c wmic logicaldisks get deviceID >> temp.txt & wmic logicaldisks get description >> temp.txt")

However you will run into encoding issues as wmic returns unicode, so when you use fileread to read it back you get a lot of extra hex characters that you have to filter through.

2.) Use winexec to call fsutil

winexec("cmd.exe /c fsutil fsinfo drives >> temp.txt ").

I believe this has less of an issue with encoding and spits back UTF-8.   If there are still some encoding issues you can use cmd switch type or chcp to change the encoding to get it to format correctly.

Sutton B.
Irvine, CA

Oct 23, 2017
9 Posts

0  |  0  

Re: List of Logical Drives

Hi Michael,

You could also try wrapping the function in a .Net wrapper DLL so that ATEasy does not handle the array and is only returned the drivers at the end. It is usually easier to wrap a function and return what you want then to force the function to work. But it sounds like you at least got it to work.


Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]