Upgrading VB6 Code

Jay1b

Well-known member
Joined
Aug 3, 2003
Messages
640
Location
Kent, Uk.
Hi, i am trying to find out the type of storage that the path sJournalDirectory is currently stored on. Such as local or network.

I believe the code below works fine in VB6, but i was wondering how to convert this into VB.Net. I already tried upgrading it, but to no avail.

Code:
 Set fs = CreateObject("Scripting.FileSystemObject")

   If fs.GetDrive(fs.GetDriveName(sJournalDirectory)).DriveType <> Fixed Then
......................
    End If
 
After about half a bloody hour looking through the .Net help (why is it so bad compared to VB6 help?) i came up with:

Code:
Dim fso As FileSystemObject
            MsgBox("S: is a " + fso.GetDrive("s:").DriveType)

But it still doesnt work, and when i tie it to a buttons click event, it closes down the current screen - it doesnt drop right out.
 
if you really want to use the scripting filesystem object , try this...
Code:
        Dim typeShell As Type = Type.GetTypeFromProgID("Scripting.FileSystemObject")
        Dim objShell As Object = Activator.CreateInstance(typeShell)
        Dim drive As Object() = {"C:\"}

        Dim drivetype As Object = typeShell.InvokeMember("Drives", Reflection.BindingFlags.GetProperty, Nothing, objShell, Nothing)
        Dim item As Object = drivetype.GetType.InvokeMember("Item", Reflection.BindingFlags.GetProperty, Nothing, drivetype, drive)
        Dim typofDrive As Integer = DirectCast(item.GetType.InvokeMember("DriveType", Reflection.BindingFlags.GetProperty, Nothing, item, Nothing), Integer)

        If typofDrive = 2 Then
            MessageBox.Show("its a hard-drive")
        ElseIf typofDrive = 3 Then
            MessageBox.Show("its a Remote-drive")
        End If

        objShell = Nothing
although you could also try looking at the Windows Management Object ;)
 
dynamic_sysop, although i have test it, and your code does work perfectly - i dont understand it, so i looked on the internet and found this:

Code:
Imports System.Management

...........................................
            Dim disks As New ManagementClass("Win32_LogicalDisk")
            Dim moc As ManagementObjectCollection = disks.GetInstances()
            Dim mo As ManagementObject
            For Each mo In moc
                Console.WriteLine("Disk type : {0}", mo("DriveType").ToString())
            Next mo
            disks.Dispose()

But it doesnt find system.management, so i would imagine its a Com i have to set a reference too. Is there an easy way of finding out which on?
 
Back
Top