0

I maintain a drive mapping utility where I work. It's only real purpose is to map network drives. It's been around for a while and has been updated through the years, as operating systems are upgraded. The code for mapping the drives is:

    Process prMapDrive;
    prMapDrive = new Process();

    prMapDrive.StartInfo.UseShellExecute = true;
    prMapDrive.StartInfo.FileName = "cmd.exe";
    prMapDrive.StartInfo.Arguments = string.Format(@"/C net use {0} {1} /persistent:{2}", sDrive, sPath, fPersist ? "Yes" : "No");
    prMapDrive.StartInfo.CreateNoWindow = true;
    prMapDrive.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

    prMapDrive.Start();
    prMapDrive.WaitForExit(); 
    prMapDrive.Close();

    prMapDrive.StartInfo.Verb = "runas";
    prMapDrive.Start();
    prMapDrive.WaitForExit();
    prMapDrive.Close();

This code works great on Windows 7 machines and I have no complaints. The complaints come in when people use it on Windows 10. When run on Windows 10, the drives are not visible. I added the following line of code, to check for the presence of the drive:

    return Directory.Exists(sDrive);

This returns True, yet when I go into explorer, I don't see the drive. If I go to a dos prompt and check for the drive using net use, I don't see it. So in spite of Directory.Exists returning True, I don't see any mapped drives. This does not appear to be failing and I suppose that on some level, it isn't. Otherwise Directory.Exists would not be returning True.

To make matters worse, this is a newer version of an older VB.NET utility. That utility works, at least for me, though there are some complaining that it doesn't work. The VB.NET code for it is:

  Dim prMapDrive As Process
  prMapDrive.StartInfo.UseShellExecute = True
  prMapDrive.StartInfo.FileName = "cmd.exe"
  prMapDrive.StartInfo.Arguments = String.Format("/C net use {0} {1} /persistent:{2}", sDrive, sPath, _
                                                 If(fPersist, "Yes", "No"))

  prMapDrive.StartInfo.CreateNoWindow = True
  prMapDrive.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

  prMapDrive.Start()
  prMapDrive.WaitForExit()
  prMapDrive.Close()

  prMapDrive.StartInfo.Verb = "runas"

  prMapDrive.Start()
  prMapDrive.WaitForExit()
  prMapDrive.Close()

  Return Directory.Exists(sDrive)

I don't see any difference between these two, other than the fact that they're using different programming languages.

Looking in the registry in Windows 7, I see drives mapped under HKCU\Network. When I look on the Windows 10 machine, I see no drives mapped. So that's one difference.

Another difference - if I use an elevated command prompt, then I can see the drives using net use, and I can access them through DOS.

So it does appear that the drives are being mapped and can be accessed from an elevated command prompt.

What am I missing? Is there some other way that I should be handling this? I used to use WNetAddConnection, but stopped using it on Windows 10 because that didn't seem to be working.

Scott
  • 1,370
  • 2
  • 9
  • 16
  • 1
    The difference might be bitness. Newer versions of Visual Studio have "any platform, prefer 32-bit" as their target for projects. Older versions just had "any platform", and thus would give you executables that ran as 64-bit on 64-bit machines. Should that make a difference when you're programmatically invoking `cmd /c net use`? Well, no, not that I'm aware of, despite all the virtualization shenanigans. But it's *a* possible difference. – Jeroen Mostert Oct 12 '17 at 19:52
  • Have you collected any data when a user reports a failure? Event logs? Console output? anything? Because right now your post amounts to throwing your hands in the air and yelling "It doesn't work!" - which is sometimes useful, but not when you are trying to get help solving a problem. – Sam Axe Oct 12 '17 at 19:55
  • I'm one of the users that it's happening to, so I can debug it appropriately. Not throwing my hands up in the air. Just looking to see if anyone else has come across this issue. The thing that gets me is Directory.Exists(sDrive) return true, which means at some level, the system recognizes that there is a drive mapped. I'm just not seeing it in explorer or DOS. – Scott Oct 12 '17 at 20:46
  • Do you have UAC enabled? Are you running the program as part of a login script (AD or local GP)? Try opening an administrative command prompt (Start cmd right-click Run as Administrator) and doing `net use` to list mapped drives. PS We are trying to leave them behind but I understand some systems still require them. – NetMage Oct 12 '17 at 22:37

0 Answers0