ASP.NET - WNetUseConnection - ERROR_INVALID_ADDRESS = 487

Asked By anbu n on 30-Sep-11 09:28 AM
this is my below code for -- WNetUseConnection

------------------
        [StructLayout(LayoutKind.Sequential)]
        private class NETRESOURCE
        {
          //public int dwScope = 0;

          public int dwScope = RESOURCE_GLOBALNET;

          //public int dwType = 0;
          public int dwType = RESOURCETYPE_ANY;

          // public int dwDisplayType = 0;
          public int dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC;

          //public int dwUsage = 0;
          public int dwUsage = RESOURCEUSAGE_NOLOCALDEVICE;

          public string lpLocalName = "";
          //public string lpRemoteName = "";

          public string lpRemoteName = "";

          public string lpComment = "";
          public string lpProvider = "";
        }


        public static string connectToRemote(string remoteUNC, string username, string password)
        {
          return connectToRemote(remoteUNC, username, password, true);
        }

        public static string connectToRemote(string remoteUNC, string username, string password, bool promptUser)
        {

         String  buffer ="";     // Drive letter assigned to resource
         String bufferlen = "";    // Size of the buffer
         String success = "";     // Additional info about API call

          //Initialize the return buffer and buffer size
          
         // buffer = Space(32);
         // bufferlen = Len(buffer);

          //remoteUNC = "192.168.1.14";
          NETRESOURCE nr = new NETRESOURCE();
          nr.dwType = RESOURCETYPE_DISK;
          //nr.dwType = RESOURCETYPE_ANY;
          nr.lpRemoteName = remoteUNC;
          //            nr.lpLocalName = "F:";

          int ret;
          if (promptUser)
           // ret = WNetUseConnection(IntPtr.Zero, nr, "", "", CONNECT_INTERACTIVE | CONNECT_PROMPT |CONNECT_REDIRECT , null, null, null);

            ret = WNetUseConnection(IntPtr.Zero, nr, "admin", "Admin", CONNECT_REDIRECT, buffer, bufferlen, success);

           // ret = WNetUseConnection(IntPtr.Zero, nr, "", "", CONNECT_INTERACTIVE | CONNECT_PROMPT, null, null, success);

          else
            ret = WNetUseConnection(IntPtr.Zero, nr, password, username, 0, null, null, null);

           // ret = WNetUseConnection(IntPtr.Zero,nr , "","",  

          if (ret == NO_ERROR) return "ok connectToRemote";
          return getErrorForNumber(ret);
        }

        public static string disconnectRemote(string remoteUNC)
        {
          int ret = WNetCancelConnection2(remoteUNC, CONNECT_UPDATE_PROFILE, false);
          if (ret == NO_ERROR) return "ok disconnectRemote";
          return getErrorForNumber(ret);
        }
------------
-->     ret = WNetUseConnection(IntPtr.Zero, nr, "admin", "Admin", CONNECT_REDIRECT, buffer, bufferlen, success);

the above line in code returns  ERROR_INVALID_ADDRESS = 487

--

can some body help.... i am unable to find remote path using WNetCancelConnection





Devil Scorpio replied to anbu n on 30-Sep-11 05:51 PM

hi,

refer this

http://support.microsoft.com/default.aspx?scid=kb;en-us;256847