Danimar 0 Denunciar post Postado Março 28, 2008 Estou tentando mapear uma unidade de rede, através de código. Esta retornando o código de erro 487 - Attempt to access invalid address. Estou usando o endereço \\10.1.1.1\lixo tentei utilizar o endereço \\servermaster\lixo que é o endereço que eu mapeio a unidade através do windows, mas ocorre o mesmo erro. gostaria de saber se alguém já passou por isso. e qual a solução.. Obrigado. Segue o código abaixo. Declare Function WNetAddConnection2 Lib "mpr.dll" Alias _ "WNetAddConnection2W" (ByVal lpNetResource As NETRESOURCE, _ ByVal lpPassword As String, _ ByVal lpUserName As String, _ ByVal dwFlags As Long) As Long Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias _ "WNetCancelConnection2W" (ByVal lpName As String, _ ByVal dwFlags As Long, _ ByVal fForce As Long) As Long <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _ Structure NETRESOURCE Dim dwScope As Long Dim dwType As Long Dim dwDisplayType As Long Dim dwUsage As Long Dim lpLocalName As String Dim lpRemoteName As String Dim lpComment As String Dim lpProvider As String End Structure Dim theNetResource As NETRESOURCE Public Const NO_ERROR = 0 Public Const CONNECT_UPDATE_PROFILE = &H1 ' The following includes all the constants defined for NETRESOURCE, ' not just the ones used in this example. Public Const RESOURCETYPE_PRINT = &H2 Public Const RESOURCETYPE_DISK = &H1 Public Const RESOURCETYPE_ANY = &H0 Public Const RESOURCE_CONNECTED = &H1 Public Const RESOURCE_REMEMBERED = &H3 Public Const RESOURCE_GLOBALNET = &H2 Public Const RESOURCEDISPLAYTYPE_DOMAIN = &H1 Public Const RESOURCEDISPLAYTYPE_GENERIC = &H0 Public Const RESOURCEDISPLAYTYPE_SERVER = &H2 Public Const RESOURCEDISPLAYTYPE_SHARE = &H3 Public Const RESOURCEUSAGE_CONNECTABLE = &H1 Public Const RESOURCEUSAGE_CONTAINER = &H2 'Constantes de erros Public Const ERROR_ACCESS_DENIED = 5& Public Const ERROR_ALREADY_ASSIGNED = 85& Public Const ERROR_BAD_DEV_TYPE = 66& Public Const ERROR_BAD_DEVICE = 1200& Public Const ERROR_BAD_NET_NAME = 67& Public Const ERROR_BAD_PROFILE = 1206& Public Const ERROR_BAD_PROVIDER = 1204& Public Const ERROR_BUSY = 170& Public Const ERROR_CANCELLED = 1223& Public Const ERROR_CANNOT_OPEN_PROFILE = 1205& Public Const ERROR_DEVICE_ALREADY_REMEMBERED = 1202& Public Const ERROR_EXTENDED_ERROR = 1208& Public Const ERROR_INVALID_PASSWORD = 86& Public Const ERROR_NO_NET_OR_BAD_PATH = 1203& Private Sub Button6_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Try Const WN_Success = &H0 theNetResource.lpRemoteName = "\\10.1.1.1\lixo" theNetResource.lpLocalName = "X:\" theNetResource.dwType = RESOURCETYPE_DISK theNetResource.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE theNetResource.dwUsage = RESOURCEUSAGE_CONNECTABLE Dim returnCode As Long = WNetAddConnection2(theNetResource, "senha", "usuario", 1) Dim msg As String Select Case returnCode Case WN_Success msg = "Sucesso" Case Else msg = "Unrecognized Error " + Str(returnCode) + "." End Select MsgBox(msg) Dim i As Long 'Desconecta i = WNetCancelConnection2(theNetResource.lpLocalName, 0, 0) Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Compartilhar este post Link para o post Compartilhar em outros sites
quintelab 91 Denunciar post Postado Março 29, 2008 Movido Plataforma .NET » Visual Studio .NET http://forum.imasters.com.br/public/style_emoticons/default/seta.gif Plataforma .NET » Windows Applications Não cheguei a testar o código mas de uma olhada neste artigo, pode ser útil: http://www.linhadecodigo.com/Dica.aspx?id=778 Abraços... Compartilhar este post Link para o post Compartilhar em outros sites