Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

 

 Set fs = CreateObject("Scripting.FileSystemObject")

  If fs.GetDrive(fs.GetDriveName(sJournalDirectory)).DriveType <> Fixed Then
......................
   End If

Posted

After about half a bloody hour looking through the .Net help (why is it so bad compared to VB6 help?) i came up with:

 

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.

  • Leaders
Posted

if you really want to use the scripting filesystem object , try this...

       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("it's a hard-drive")
       ElseIf typofDrive = 3 Then
           MessageBox.Show("it's a Remote-drive")
       End If

       objShell = Nothing

although you could also try looking at the Windows Management Object ;)

Posted

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:

 

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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...