none
Net use en vb9 RRS feed

Réponses

  • Bonjour Fred,

    Tu as tout ce qu'il te faut pour mapper un lecteur réseau ici :
    http://www.csharpfr.com/code.aspx?ID=34841


    Voilà la source en VB.Net :


    <DllImport("mpr.dll")> _
    Public Shared Function WNetAddConnection3( <[In]()> _
    ByVal hwndOwner As IntPtr, <[In]()> _
    ByRef lpNetResource As NETRESOURCE, <[In]()> _
    ByVal lpPassword As String, <[In]()> _
    ByVal lpUsername As String, <[In]()> _
    ByVal dwFlags As WNetAddConnectionFlags) As UInteger
    End Function
    
    
    <DllImport("mpr.dll")> _
    Public Shared Function WNetCancelConnection2( <[In]()> _
    ByVal lpName As String, <[In]()> _
    ByVal dwFlags As WNetCancelConnectionFlags, <[In]()> _
    ByVal fForce As Boolean) As UInteger
    End Function
    
    
    ' les méthodes de connexion disponibles
    Public Shared Function ConnectDisk(ByVal remoteName As String) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal mode As PromptMode) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal hwndOwner As IntPtr) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal mode As PromptMode, ByVal hwndOwner As IntPtr) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal user As String, ByVal pass As String) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal user As String, ByVal pass As String, ByVal mode As PromptMode) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal user As String, ByVal pass As String, ByVal hwndOwner As IntPtr) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal user As String, ByVal pass As String, ByVal mode As PromptMode, ByVal hwndOwner As IntPtr) As NetworkShare.NetworkShare
    End Function
    
    ' la méthode qui effectue l'appel de WNetAddConnection3
    Private Shared Function ConnectDiskInternal(ByVal remoteName As String, ByVal user As String, ByVal pass As String, ByVal flags As NativeMethods.WNetAddConnectionFlags, ByVal hwndOwner As IntPtr) As NetworkShare
    Dim share As NetworkShare = Nothing
    
    Try
    Dim ret As UInteger
    Dim netres As New NETRESOURCE()
    netres.dwType = NETRESOURCE.Type.RESOURCETYPE_DISK
    netres.lpRemoteName = remoteName
    
    ret = NativeMethods.WNetAddConnection3(hwndOwner, netres, pass, user, flags)
    
    If ret = NativeMethods.NO_ERROR Then
    share = New NetworkShare(remoteName)
    Else
    share = Nothing
    End If
    Catch
    share = Nothing
    End Try
    
    Return share
    End Function


    En espérant que cela t'aide,

    Thomas

    Thomas Aimonetti - C# - Sharplog Engineering - http://www.sharplog.fr
    vendredi 15 janvier 2010 14:38
  • Bonjour,

    Vous pouvez toujours utiliser la classe Process. C'est un peu plus court en ligne de code mais moins riche en fonctionnalités que la proposition de Tom.

     Process.Start("net", "use w: \\monPc\monPartage")


    Cordialement,

    Mathieu
    Mathieu Francesch Sharplog Engineering
    • Proposé comme réponse Thomas Aimonetti vendredi 15 janvier 2010 20:52
    • Marqué comme réponse fred75 samedi 16 janvier 2010 09:06
    vendredi 15 janvier 2010 19:39

Toutes les réponses

  • Bonjour Fred,

    Tu as tout ce qu'il te faut pour mapper un lecteur réseau ici :
    http://www.csharpfr.com/code.aspx?ID=34841


    Voilà la source en VB.Net :


    <DllImport("mpr.dll")> _
    Public Shared Function WNetAddConnection3( <[In]()> _
    ByVal hwndOwner As IntPtr, <[In]()> _
    ByRef lpNetResource As NETRESOURCE, <[In]()> _
    ByVal lpPassword As String, <[In]()> _
    ByVal lpUsername As String, <[In]()> _
    ByVal dwFlags As WNetAddConnectionFlags) As UInteger
    End Function
    
    
    <DllImport("mpr.dll")> _
    Public Shared Function WNetCancelConnection2( <[In]()> _
    ByVal lpName As String, <[In]()> _
    ByVal dwFlags As WNetCancelConnectionFlags, <[In]()> _
    ByVal fForce As Boolean) As UInteger
    End Function
    
    
    ' les méthodes de connexion disponibles
    Public Shared Function ConnectDisk(ByVal remoteName As String) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal mode As PromptMode) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal hwndOwner As IntPtr) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal mode As PromptMode, ByVal hwndOwner As IntPtr) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal user As String, ByVal pass As String) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal user As String, ByVal pass As String, ByVal mode As PromptMode) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal user As String, ByVal pass As String, ByVal hwndOwner As IntPtr) As NetworkShare.NetworkShare
    End Function
    Public Shared Function ConnectDisk(ByVal remoteName As String, ByVal user As String, ByVal pass As String, ByVal mode As PromptMode, ByVal hwndOwner As IntPtr) As NetworkShare.NetworkShare
    End Function
    
    ' la méthode qui effectue l'appel de WNetAddConnection3
    Private Shared Function ConnectDiskInternal(ByVal remoteName As String, ByVal user As String, ByVal pass As String, ByVal flags As NativeMethods.WNetAddConnectionFlags, ByVal hwndOwner As IntPtr) As NetworkShare
    Dim share As NetworkShare = Nothing
    
    Try
    Dim ret As UInteger
    Dim netres As New NETRESOURCE()
    netres.dwType = NETRESOURCE.Type.RESOURCETYPE_DISK
    netres.lpRemoteName = remoteName
    
    ret = NativeMethods.WNetAddConnection3(hwndOwner, netres, pass, user, flags)
    
    If ret = NativeMethods.NO_ERROR Then
    share = New NetworkShare(remoteName)
    Else
    share = Nothing
    End If
    Catch
    share = Nothing
    End Try
    
    Return share
    End Function


    En espérant que cela t'aide,

    Thomas

    Thomas Aimonetti - C# - Sharplog Engineering - http://www.sharplog.fr
    vendredi 15 janvier 2010 14:38
  • ok
    Je pensais qu'il y aurait une solution .net plus simple comme une sous-classe dans System
    je vais essayer cette solution.
    merci


    fred
    vendredi 15 janvier 2010 17:26
  • Bonjour,

    Vous pouvez toujours utiliser la classe Process. C'est un peu plus court en ligne de code mais moins riche en fonctionnalités que la proposition de Tom.

     Process.Start("net", "use w: \\monPc\monPartage")


    Cordialement,

    Mathieu
    Mathieu Francesch Sharplog Engineering
    • Proposé comme réponse Thomas Aimonetti vendredi 15 janvier 2010 20:52
    • Marqué comme réponse fred75 samedi 16 janvier 2010 09:06
    vendredi 15 janvier 2010 19:39
  • Merci Mathieu,
    c'est beaucoup plus simple

    fred
    vendredi 15 janvier 2010 20:13