here is my code, basically, i want to assign drive letter "H“ to a removable usb drive
but when I try to set value for drive letter, there is no exception or error, nth happens.
problem seems to be following line, but i couldnt find out how to fix it.
mo.SetPropertyValue("DriveLetter","H:");
im using win7 and tested with administrator previllage when running debug.
can someone please help?
public static void Main(string[] args) { RetrieveDiskInfo_DriveLetter rdd = new RetrieveDiskInfo_DriveLetter(); ManagementClass mc = new ManagementClass("Win32_Volume"); ManagementObjectCollection moc =mc.GetInstances(); if(moc.Count!=0) { try{ foreach (ManagementObject mo in moc) { if (mo["DriveType"].ToString() == "2") { Console.WriteLine(mo["Drivetype"].ToString()); Console.WriteLine(mo["DeviceID"].ToString()); mo.SetPropertyValue("DriveLetter","H:"); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }
ummm thanks for the reply, it works now on win7
but somehow it gets unhandled exception on WINXP
the debugger points to ManagementObjectCollection moc = mc.GetInstances();
do you know how come this happens??
Ikelca
ASKER
nvm, i just found out win32_volume is not available to winxp and earlier windows.....
thanks guys
Open in new window