Announcement

Collapse
No announcement yet.

net Use per VB2005

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • net Use per VB2005

    Hallo zusammen,
    ich kenne den Befel net use mit welchem man per Batchdatei z.B. eine Datei/Ordnerfreigabe über ein Netzwerk mappen kann....

    Gibt es im VB.Net eine Möglichkeit so etwas per Code zu erledigen...?

    Falls ja, wäre ich über ein paar Zeilen Code dankbar....

  • #2
    Hallo, ich denke es gibt wie immer mehrere Lösungen für ein und das gleiche Problem

    http://www.codeguru.com/csharp/cshar...le.php/c12357/

    oder benutze einfach die WNetAddConnection der WinAPI
    wiiapi.de
    wiisdk.de

    Comment


    • #3
      Ich denke damit könnte ich was anfangen....
      ....aber das ist für C#. Ich benötige was für VB....

      Comment


      • #4
        Ich bin da jetzt schon ein ganzes Stück voran gekommen:

        Es klappt wenn ich ein Laufwerk ohne User und Password mappe wenn ich die den den Paramentern möchte funktioniert es nicht...

        Hat jamand eine Idee.....? Hier meine Code....

        Code:
        Public Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (ByRef lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Integer) As Integer
        
          Public Declare Function WNetCancelConnection2 Lib "mpr" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As Integer) As Integer
        
          <Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> Public Structure NETRESOURCE
            Public dwScope As Integer
            Public dwType As Integer
            Public dwDisplayType As Integer
            Public dwUsage As Integer
            Public lpLocalName As String
            Public lpRemoteName As String
            Public lpComment As String
            Public lpProvider As String
          End Structure
        
          Public Const ForceDisconnect As Integer = 1
          Public Const RESOURCETYPE_DISK As Long = &H1
        
          Public Function MapDrive(ByVal DriveLetter As String, ByVal UNCPath As String, ByVal UserName As String, ByVal PassWord As String, ByRef errMsg As String) As Boolean
        
            Dim nr As NETRESOURCE
        
            nr = New NETRESOURCE
            nr.lpRemoteName = UNCPath
            nr.lpLocalName = DriveLetter & ":"
            If UserName = String.Empty Then UserName = Nothing '(add parameters to pass this if necessary)
            If PassWord = String.Empty Then PassWord = Nothing '(add parameters to pass this if necessary)
            nr.dwType = RESOURCETYPE_DISK
        
            Dim result As Integer
            Try
              result = WNetAddConnection2(nr, PassWord, UserName, 0)
            Catch ex As Exception
              errMsg = ex.Message
            End Try
        
            errMsg = result.ToString
        
            If result = 0 Then
              Return True
            Else
              Return False
            End If
          End Function
        
          Public Function UnMapDrive(ByVal DriveLetter As String) As Boolean
            Dim rc As Integer
            rc = WNetCancelConnection2(DriveLetter & ":", 0, ForceDisconnect)
        
            If rc = 0 Then
              Return True
            Else
              Return False
            End If
        
          End Function

        Comment

        Working...
        X