Link to home
Start Free TrialLog in
Avatar of Ikelca
IkelcaFlag for Canada

asked on

setPropertyValue does not work with win32_volume?

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());

               }
                
            
        }
      }

Open in new window

Avatar of crysallus
crysallus
Flag of Australia image

Have you tried putting a slash at the end of the drive letter?

mo.SetPropertyValue("DriveLetter",@"H:\");

Open in new window

Avatar of Ikelca

ASKER

tried, it does not work
Avatar of Ikelca

ASKER

and no error msg, this is weird
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ikelca

ASKER

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??
Avatar of Ikelca

ASKER

nvm, i just found out win32_volume is not available to winxp and earlier windows.....
thanks guys