Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm tryin to assign a drive letter to an unmounted drive using C#, but my code doesn't seem to work

What I have tried:

ManagementObjectSearcher disks = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Volume WHERE label = 'label_name'");
                  foreach (ManagementObject disk in disks.Get())
                  {
                      disk.Get();
                      disk["DriveLetter"] = "M:";
                      disk.Put();
                  }
Posted
Updated 6-Jul-17 22:53pm
v2

1 solution

Quote:
I'm tryin to assign a drive letter to an unmounted drive using C#, but my code doesn't seem to work

Probably because letters are assigned to drives when windows mount them.
So unmounted volumes have no letter.

Just curious: what is the interest to assign a letter to an unmounted volume?
 
Share this answer
 
Comments
Member 13297940 7-Jul-17 7:23am    
I understand drive letters are not assigned to an unmounted drive, that is why i'm getting the volume label and then assigning the Drive letter.

I'm mounting this drive because i need to access it's files through my application.
Patrice T 7-Jul-17 7:47am    
Why don't you just ask windows to mount the volume ?
Windows knows which letter was used by the volume last time it was mounted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900