wnet

Calling WNetAddConnection2 with empty local name

前提是你 提交于 2019-12-24 02:24:10
问题 I have a small program that simply checks if a specified file is located on a specified network drive that is not mapped on the computer. To check this I temporarily map to the network location, check if the file exists and than unmap the drive. I now figured out that I can call WNetAddConnection2 with an empty local name (MSDN: If the string is empty, or if lpLocalName is NULL, the function makes a connection to the network resource without redirecting a local device.). Just for showing the

WNetAddConnection2 returns Error 1200 - Local name is valid

半世苍凉 提交于 2019-12-12 10:44:51
问题 I'm trying to connect a share (let's say \server\folder) to my local device X: [DllImport("Mpr.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern int WNetAddConnection2( [In] NetResource lpNetResource, string lpPassword, string lpUsername, int flags ); public static bool Connect(string remoteName, string localName, bool persistent) { if (!IsLocalPathValid(localName)) return false; var r = new NetResource { dwScope = ResourceScope.RESOURCE_GLOBALNET, dwType =