How to change drive letters (was: Can I use Visual C to program system tools)

Terry Foster 0 Reputation points
2024-07-01T22:19:00.44+00:00

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.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,492 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,751 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,260 questions
{count} votes

2 answers

Sort by: Most helpful
  1. S.Sengupta 16,651 Reputation points MVP
    2024-07-02T00:07:16.7633333+00:00
    1. Create a Windows Forms application in Visual Studio.
    2. Use the System.IO.DriveInfo class to detect and list drives.
    3. Use the System.Management namespace to change drive letters.
    4. Create a simple GUI with a list of drives and a button to change the letter.
    2 people found this answer helpful.
    0 comments No comments

  2. Rob Caplan - MSFT 5,427 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.

    1 person found this answer helpful.
    0 comments No comments