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

发布于 2024-10-07 18:22:04 字数 680 浏览 5 评论 0原文

我正在使用 WNetAddConnection2< 将网络驱动器安装到 Windows /a> 工作正常,但在默认情况下安装驱动器时,它将名称指定为 Server IP 和 FolderName ,

“NAS 服务器 (172.24.17.116)”(R:) 上的 NDSTestFolder

我需要使用 SetVolumeLabel 但这对于网络驱动器来说失败,并显示参数无效,而 SetVolumeLabel 对于本地驱动器工作正常。

有没有办法可以重命名或重新标记网络驱动器?这样我就可以改变

“NAS 服务器 (172.24.17.116)”(R:) 上的 NDSTestFolder

NDS@MyFolder (R:)

I am mounting a network drive to windows using WNetAddConnection2 which is working fine but while mounting the drive by default it assigns the name as Server IP and FolderName ,

NDSTestFolder on 'NAS server (172.24.17.116)'(R:)

I need to rename the drive label using SetVolumeLabel but this fails for the network drive saying invalid parameter while SetVolumeLabel works fine for the local drives.

Is there a way I can rename or relabel a network drive? So that I can change

NDSTestFolder on 'NAS server (172.24.17.116)'(R:)

to

NDS@MyFolder (R:)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

剑心龙吟 2024-10-14 18:22:04

将您的脚本翻译成 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();
   }
}

Translated your script into 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();
   }
}
靖瑶 2024-10-14 18:22:04

不确定是否有用于此目的的 API,但字符串存储在注册表中的以下位置:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2

通过解析那里的项找到正确的子项(它可能看起来像“##172.24”) .17.116#NDSTestFolder" )并将 _LabelFromReg 值更改为您喜欢的任何值...

Not sure if there's an API for this but the strings are stored in the registry under:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2

Find the correct subkey by parsing the keys there (it will probably look like "##172.24.17.116#NDSTestFolder" ) and change the _LabelFromReg value to whatever you like...

岁月静好 2024-10-14 18:22:04

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

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";

I tried using vb script for renaming thr drive:

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";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文