如何重命名或重新标记networking驱动器标签

我使用WNetAddConnection2挂载到Windowsnetworking驱动器,它工作正常,但默认挂载驱动器时,它将名称分配为服务器IP和文件夹名称,

'NAS server(172.24.17.116)'(R :)上的NDSTestFolder

我需要使用SetVolumeLabel重命名驱动器标签,但是对于networking驱动器说无效的参数,而SetVolumeLabel适用于本地驱动器时失败

有没有一种方法可以重新命名或重新标记networking驱动器? 所以我可以改变

'NAS server(172.24.17.116)'(R :)上的NDSTestFolder

NDS @ MyFolder(R 🙂

Solutions Collecting From Web of "如何重命名或重新标记networking驱动器标签"

将您的脚本翻译成C ++:

#include <shldisp.h> void RenameDrive(BSTR strNewName, BSTR strDriveLetter) { IShellDispatch* pShellDispatch = NULL; HRESULT hr = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void**)&pShellDispatch); if (SUCCEEDED(hr) && pShellDispatch) { Folder* pFolder = NULL; VARIANT vt = {}; VariantInit(&vt); vt.vt = VT_BSTR; vt.bstrVal = strDriveLetter; hr = pShellDispatch->NameSpace(vt, &pFolder); VariantClear(&vt); if (SUCCEEDED(hr) && pFolder) { Folder2* pFolder2 = NULL; hr = pFolder->QueryInterface(IID_Folder2, (void**)&pFolder2); if (SUCCEEDED(hr) && pFolder2) { FolderItem* pFolderItem = NULL; hr = pFolder2->get_Self(&pFolderItem); if (SUCCEEDED(hr) && pFolderItem) { pFolderItem->put_Name(strNewName); pFolderItem->Release(); } pFolder2->Release(); } pFolder->Release(); } pShellDispatch->Release(); } } 

不知道是否有一个API,但这些字符串存储在注册表下:

HKEY_CURRENT_USER \软件\微软\的Windows \ CurrentVersion \ Explorer中\ MountPoints2

通过解析那里的键找到正确的子键(它可能看起来像“## 172.24.17.116#NDSTestFolder”)并将_LabelFromReg值更改为任何你喜欢的…

我尝试使用VB脚本重命名thr驱动器:

 LPCTSTR szCode = "Function RenameDrive(strNewName,strDriveLetter) \r\n\ Dim objShell \r\n\ Set objShell = CreateObject(\"Shell.Application\") \r\n\ 'if objShell is Not Nothing Then \r\n\ objShell.NameSpace(strDriveLetter).Self.Name = strNewName \r\n\ 'End if \r\n\ End Function";