|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Drive Defined - The Dotnet Way?for a specific drive type (ie fixed, CD, remote). This is done with the File System Object and other scripting objects along with a for loop: Dim fso As New Scripting.FileSystemObject Dim Drives As Scripting.Drives = fso.Drives Dim Drive As Scripting.Drive For Each Drive In Drives If (Drive.DriveType = Scripting.DriveTypeConst.Fixed) Then *** do something with local fixed drive only ** End If Next However, what if I know the drive I want to check. How do I assign the proper letter to a single drive instance? It appears that the methods for the drive class are read only and somehow assigned values internally during the for loop assignment. I can't create a drive object for a given drive letter and then access the methods like "drivetypecont" on that single drive. What is the dotnet solution to this issue? Not just a work around. I have a work around already. -- Donald G Plugge System Manager NIH/NCI/EIB Flow Cytometry (301)435-6429 Donald wrote:
> However, what if I know the drive I want to check. How do I assign the I found this sample on MSDN, hopefully it will help you look in the> proper letter to a single drive instance? right places: >> This example finds the amount of free disk space on the C: drive of thelocal computer. Example Public Function GetDiskSpace() As System.UInt64 Dim diskClass As _ New System.Management.ManagementClass("Win32_LogicalDisk") Dim disks As System.Management.ManagementObjectCollection = _ diskClass.GetInstances() Dim disk As System.Management.ManagementObject Dim space As System.UInt64 For Each disk In disks If CStr(disk("Name")) = "C:" Then space = CType(disk("FreeSpace"), System.UInt64) End If Next disk Return space End Function >> Messy, huh?-- Larry Lard Replies to group please Larry,
Thanks for the example. Yes, I did look at and use the Management Class, previously. However, as you say, "Messy". I can't imagine that this is the "dotnet way". Maybe version 2.0 will have an answer. Don Show quote "Larry Lard" <larryl***@hotmail.com> wrote in message news:1140099928.516147.193990@g44g2000cwa.googlegroups.com... > > Donald wrote: >> However, what if I know the drive I want to check. How do I assign the >> proper letter to a single drive instance? > > I found this sample on MSDN, hopefully it will help you look in the > right places: >>> > This example finds the amount of free disk space on the C: drive of the > local computer. > > Example > Public Function GetDiskSpace() As System.UInt64 > Dim diskClass As _ > New System.Management.ManagementClass("Win32_LogicalDisk") > Dim disks As System.Management.ManagementObjectCollection = _ > diskClass.GetInstances() > Dim disk As System.Management.ManagementObject > Dim space As System.UInt64 > For Each disk In disks > If CStr(disk("Name")) = "C:" Then > space = CType(disk("FreeSpace"), System.UInt64) > End If > Next disk > Return space > End Function >>> > > Messy, huh? > > -- > Larry Lard > Replies to group please > Donald wrote:
> Larry, It is worse than messy. I was absolutely aghast when I first saw that > > Thanks for the example. Yes, I did look at and use the Management > Class, previously. However, as you say, "Messy". I can't imagine > that this is the "dotnet way". Maybe version 2.0 will have an answer. Microsoft recommended WMI to access what a drive type is when a p/invoke call is simple. WMI is fine when you have *no other option*. The problem with WMI is that you have to make a COM interop call to a local COM server. That is, you have to ask another process. If you use pinvoke to the Win32 functions you make a call to a DLL that is already loaded in your process. Luckily .NET 2.0 has a new class called DriveInfo that gives you access to drives. I rant a bit about this issue in my security workshop: http://www.grimes.demon.co.uk/workshops/secWSSeven.htm#custom_cas_permission Richard -- Free .NET tutorials, Fusion: http://www.grimes.demon.co.uk/workshops/fusionWS.htm Security: http://www.grimes.demon.co.uk/workshops/securityWS.htm |
|||||||||||||||||||||||