I\'m writing a piece of software which maps a network drive using the WNetAddConnection2 API. Just in case it\'s relevant, this is a WebDAV drive, rather than a normal SMB shar
You could use PowerShell in your C# code, the https://msdn.microsoft.com/en-us/library/system.management.automation.powershell(v=vs.85).aspx
Change DriveLetter E
to Q
with PowerShell
$drive = Get-WmiObject -Class win32_volume -Filter "DriveLetter = 'e:'"
Set-WmiInstance -input $drive -Arguments @{DriveLetter="Q:"; Label="Label"}
I know the question is old already but I had exactly the same issue with the renaming of a webdav drive letters and found a solution.
The problem occurs, if you ever connected your webDav drive with the address like:
https://www.myurl.com:5006/myFolder
Using this url-scheme will result in an registry entry in:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2
A "DavWWWRoot" will automatically inserted into your given address:
##myurl.com@SSL@5006#DavWWWRoot#myFolder
Also if you remove this drive, the RegistryEntry persists and will prevent you from renaming the drive via script also if you already made it to mount a drive with a registry-entry without the "DavWWWRoot" string in it. (using different url-scheme)
When you try to automatically rename the drives label with the method showed by Dan, the new name will be placed unter a new RegistryEntry with a different path (without the "DavWWWRoot") and the new name will not be used.
The solution is:
\\www.myurl.com@SSL@5006\myFolder
##myurl.com@SSL@5006#myFolder
Shell32.Shell shell = new Shell32.Shell();
((Shell32.Folder2) shell.NameSpace("Z:")).Self.Name = "Shell";