Click here to Skip to main content
16,013,642 members

Comments by h3nr1qu3 (Top 1 by date)

h3nr1qu3 28-May-16 16:28pm View    
Good afternoon.
I found an interesting code, most could not get satisfactory results alone you could help me.
It changes the letter specifies, not the volume label.
eg if the flash drive is the letter "R: \" to run the command it switches to "p" :) .More when flash drive is plugged into the machine
the system can assign a different letter "R: \" so my intention and assign the letter by name stick "test."

Public Class Form1

    Private Property StringComparer As String

    Private Property objWMIService The Object

    Private Property colVolumes The Object

    Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        StringComparer = "."
        objWMIService = GetObject ( "winmgmts" _
            & "{ImpersonationLevel = impersonate}! \\" & StringComparer & "\ root \ cimv2")


        colVolumes = objWMIService.ExecQuery ("Select * from Win32_Volume Where Name = 'R:\\'")

        For Each objVolume In colVolumes
            objVolume.DriveLetter = "P"
            objVolume.Put_ ()
        Next

    end Sub


end Class