Difference between WNetAddConnection2() and NetUseAdd()
Asked Answered
S

1

7

I'm mounting a remote drive locally (see User/password problems with GetVolumeNameForVolumeMountPoint() (Windows remote drive mount?))

QUESTION: What is the difference between WNetAddConnection2() and NetUseAdd()? It appears they each permit you to assign a remote drive path to a local drive letter providing username and password.

Further, I can call WNetAddConnection2() specifying a local drive letter (works), or specifying "NULL" for the local drive letter, and the console net use command will show success mounting the remote drive to "nothing" locally -- as you would expect -- but I'm unsure of the purpose for that kind of result. My hope was that it would establish "logon credentials" between the local system/process and the remote computer so that other calls to ::GetVolumeNameForVolumeMountPoint() would have correct username/password context, but that doesn't work for me.

The ultimate goal is to mount the remote drive locally without a local drive letter (to something like a local GUID path share because all 26 local drive letters are already in use), but all calls to ::GetVolumeNameForVolumeMountPoint() fail with Logon failure: unknown user name or bad password, even after I successfully mount remotely to a local drive letter providing the remote username and password (currently using WNetAddConnection2()).

Spectroscopy answered 2/7, 2011 at 12:15 Comment(2)
NetUseAdd- You could just pass null as the local drive letter, no local drive will be mapped and you can use unc path format to access the remote resource.Catabasis
@weeyoung, that's no difference, works on bothBekha
S
4

NetUseAdd() makes the connection visible in Windows Explorer, while WNetUseConnection() and WNetAddConnection() do not make the connection visible in Windows Explorer.

Surreptitious answered 2/7, 2011 at 12:20 Comment(3)
FYI, today I confirmed that the drive letters mounted with WNetUseConnection2() are visible through Windows Explorer (on Windows Vista). Weird.Spectroscopy
Unaccepted and confirmed, they both expose in Windows Explorer which is absolutely not what I want, if anyone would happen to have a solution to that, I would be happy to hear about it ;o)Bekha
@Spectroscopy Where is there documentation for WNetUseConnection2? (Or did you mean WNetAddConnection2?)Clumsy

© 2022 - 2024 — McMap. All rights reserved.