Jay1b Posted February 2, 2004 Posted February 2, 2004 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 Quote
Jay1b Posted February 2, 2004 Author Posted February 2, 2004 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. Quote
Leaders dynamic_sysop Posted February 2, 2004 Leaders Posted February 2, 2004 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 ;) Quote
Jay1b Posted February 2, 2004 Author Posted February 2, 2004 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? Quote
Administrators PlausiblyDamp Posted February 2, 2004 Administrators Posted February 2, 2004 If you add a reference you can select System.Management, no need to go to the COM tab at all. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.