映射的drivelabel windows 7问题

时间:2015-07-17 07:00:35

标签: c# windows webdav

我对于使用Windows 7操作系统将驱动器映射到Windows的LABEL问题感到疯狂。场景;

我们需要在用户登录到计算机后立即映射驱动器。除了Windows 7之外,其他操作系统版本似乎也能正常工作。适用于Windows 7的步骤;

  1. 在Windows 7中启动的EXE(由我们制作的c#)
  2. EXE已正确映射驱动器
  3. 用户已退出
  4. 已登录
  5. 再次exe试图映射驱动器(它注册为启动exe)
  6. 映射的驱动器标签变为“网络驱动器”(不确定如何)
  7. 我们在注册表中设置了正确的值,如下图所示;

    enter image description here

    问题在这里;

    enter image description here

    问题仅在我们注销和登录时发生。如果我们手动启动exe,它运行正常......

    我还尝试在映射驱动之前删除所有这些注册表,假设它可能是缓存或其他东西,但没有任何帮助..

    我们正在使用zMapDrive映射驱动器;

    //create struct data
    structNetResource stNetRes = new structNetResource();
    stNetRes.iScope = 2;
    stNetRes.iType = RESOURCETYPE_DISK;
    stNetRes.iDisplayType = 3;
    stNetRes.iUsage = 1;
    stNetRes.sRemoteName = ls_ShareName;
    stNetRes.sLocalName = ls_Drive;       
    //prepare params
    int iFlags = 0;
    if (lf_SaveCredentials) { iFlags += CONNECT_CMD_SAVECRED; }
    if (lf_Persistent) { iFlags += CONNECT_UPDATE_PROFILE; }
    if (ls_PromptForCredentials) { iFlags += CONNECT_INTERACTIVE + CONNECT_PROMPT; }
    if (psUsername == "") { psUsername = null; }
    if (psPassword == "") { psPassword = null; }
    //if force, unmap ready for new connection
    if (lf_Force) { try { zUnMapDrive(true); } catch { } }
    //call and return
    int i = WNetAddConnection2A(ref stNetRes, psPassword, psUsername, iFlags);
    if (i > 0) { throw new System.ComponentModel.Win32Exception(i); }
    

1 个答案:

答案 0 :(得分:0)

也许一个简单的PowerShell脚本,重命名网络驱动器对你有用吗?然后,您可以在每次用户登录时使用Task Scheduler运行它。

$Rename = New-Object -ComObject Shell.Application
$Net = New-Object -ComObject WScript.Network

# map the drive if the path doesn't exist
If (!(Test-Path Z:))
{
    $Net.MapNetworkDrive("Z:", '\\SERVER_ADDRESS\Directory', $false, "user", "password")
}

# change the drive name
$Rename.NameSpace("Z:\").Self.Name = "MyNetDriveLabel"

根据我的经验,在Windows 7中对网络映射驱动器的支持有点不对,所以我在一些Win7机器上使用了类似的解决方法。