- Create a Windows Forms application in Visual Studio.
- Use the System.IO.DriveInfo class to detect and list drives.
- Use the System.Management namespace to change drive letters.
- Create a simple GUI with a list of drives and a button to change the letter.
How to change drive letters (was: Can I use Visual C to program system tools)
I need to be able to write a tool that can change the drive letter in my application.
When I insert a usb hard drive the program recognises the volume it should be with the drive letter in [] brackets in the label.
When I insert the usb drive sometimes the computer puts wrong drive letter and I want to write a simple program to correct this with one click.
I have tried Visual Basic 2010 but cannot get anywhere.
I am told I need C, C++ or maybe Visual C but want to be sure Visual C can manage system level management before I go through the learning curve.
What is the best way to go about creating a visual tool with system (drive letter changing) facilities please.
Thank you in advance for any replies.
3 answers
Sort by: Most helpful
-
S.Sengupta 19,496 Reputation points MVP
2024-07-02T00:07:16.7633333+00:00 -
Rob Caplan - MSFT 5,537 Reputation points Microsoft Employee
2024-07-01T23:08:32.2133333+00:00 You can change drive letters with the Win32 API. See Editing Drive Letter Assignments. You can call the Win32 API from any language that can call native API, including C, C++, and (via Platform Invoke (P/Invoke)) C# or VB.Net.
That said, it will probably be easier to script the change from PowerShell rather than writing code. I've updated your title and added that tag for you so the experts in that area can chime in.
-
Rich Matheisen 46,811 Reputation points
2024-07-03T18:33:30.8766667+00:00 Have a look at the C# code here: https://stackoverflow.com/questions/5084297/c-sharp-how-to-change-the-drive-letter-of-the-cdrom-from-d-to-z
Use that as a starting point.