Announcement

Collapse
No announcement yet.

RasApi32.DLL an-/steuern (VB.NET)

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

  • RasApi32.DLL an-/steuern (VB.NET)

    Hallo zusammen,

    ich versuche seit Tagen die RasApi32.DLL über eine Anwendung (geschrieben mit VB.NET) anzusprechen.

    Die einzige Funktion die ich bis jetzt ans "Laufen" bekommen habe, ich der RasErrorHandler.

    Ich würde aber auch gerne die anderen Funktionen nutzen wollen. Zum Beilspiel die Erstellung eines Telefonbucheintrages und das Löschen, verbinden und trennen von Netzwerkverbindungen u.s.w.

    Kann mir hiermit einer von Euch behilflich sein - oder hat jemand vielleicht eine Idee wo ich zu diesem Thema was finden kann.

    Google und MSDN haben noch nicht so richtig weiter helfen können.

    Danke
    Olaf

  • #2
    Hallo

    Um dein Problem Schritt für Schritt lösen zu können wäre es hilfreich, wenn Du konkreten Kode posten würdest, welcher eben nicht läuft, was die Fehler sind, etc.

    Aber nicht die ganze Appl., sondern nur die Problemzonen, oder mal eines... so gehts wahrscheinlich am besten.

    Gruss Simon

    Comment


    • #3
      RasApi32.DLL

      Hier der nicht funktionierende Code:

      Code:
          Public Structure RASIPADDR
              Public a As Byte
              Public b As Byte
              Public c As Byte
              Public d As Byte
          End Structure
      
          Public Structure GUID
              Public Data1 As Int32
              Public Data2 As Int32
              Public Data3 As Int32
              Public Data4() As Byte
          End Structure
      
          Public Structure RASENTRY
              Public dwSize As Int32
              Public dwfOptions As Int32
              'Location/phone number.
              Public dwCountryID As Int32
              Public dwCountryCode As Int32
              Public szAreaCode() As Byte
              Public szLocalPhoneNumber() As Byte
              Public dwAlternateOffset As Int32
              'PPP/Ip.
              Public ipaddr As RASIPADDR
              Public ipaddrDns As RASIPADDR
              Public ipaddrDnsAlt As RASIPADDR
              Public ipaddrWins As RASIPADDR
              Public ipaddrWinsAlt As RASIPADDR
              'Framing
              Public dwFrameSize As Int32
              Public dwfNetProtocols As Int32
              Public dwFramingProtocol As Int32
              'Scripting
              Public szScript() As Byte
              'Autodial
              Public szAutodialDll() As Byte
              Public szAutodialFunc() As Byte
              'Devices
              Public szDeviceType() As Byte
              Public szDeviceName() As Byte
              'X.25
              Public szX25PadType() As Byte
              Public szX25Address() As Byte
              Public szX25Facilities() As Byte
              Public szX25UserData() As Byte
              Public dwChannels As Int32
              'Reserved
              Public dwReserved1 As Int32
              Public dwReserved2 As Int32
              '
              Public dwSubEntries As Int32
              Public dwDialMode As Int32
              Public dwDialExtraPercent As Int32
              Public dwDialExtraSampleSeconds As Int32
              Public dwHangUpExtraPercent As Int32
              Public dwHangUpExtraSampleSeconds As Int32
              Public dwIdleDisconnectSeconds As Int32
              Public dwType As Int32
              Public dwEncryptionType As Int32
              Public dwCustomAuthKey As Int32
              Public guidId As GUID
              Public szCustomDialDll() As Byte
              Public dwVpnStrategy As Int32
              Public dwfOptions2 As Int32
              Public dwfOptions3 As Int32
              Public szDnsSuffix() As Byte
              Public dwTcpWindowSize As Int32
              Public szPrerequisitePbk() As Byte
              Public szPrerequisiteEntry() As Byte
              Public dwRedialCount As Int32
              Public dwRedialPause As Int32
          End Structure
      
          Public Structure RASCREDENTIALS
              Public dwSize As Int32
              Public dwMask As Int32
              Public szUserName() As Byte
              Public szPassword() As Byte
              Public szDomain() As Byte
          End Structure
      
      
          <DllImport("rasapi32.dll", EntryPoint:="RasSetEntryPropertiesA", _
                  SetLastError:=True, _
                  ExactSpelling:=True, _
                  CallingConvention:=CallingConvention.StdCall)> _
          Public Function RasSetEntryProperties( _
                  ByVal lpszPhonebook As String, _
                  ByVal lpszEntry As String, _
                  ByRef lpRasEntry As RASENTRY, _
                  ByVal dwEntryInfoSize As Int32, _
                  ByVal lpbDeviceInfo As Int32, _
                  ByVal dwDeviceInfoSize As Int16) As Int32
          End Function
      
          <DllImport("rasapi32.dll", EntryPoint:="RasSetCredentialsA", _
                   SetLastError:=True, _
                   ExactSpelling:=True, _
                   CallingConvention:=CallingConvention.StdCall)> _
          Public Function RasSetCredentials( _
                  ByVal lpszPhonebook As String, _
                  ByVal lpszEntry As String, _
                  ByRef lpCredentials As RASCREDENTIALS, _
                  ByVal fClearCredentials As Int32) As Int32
          End Function
      
          Public Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (ByRef hpvDest As Byte, ByVal hpvSource As String, ByVal cbCopy As Int32)
      
          Public Sub VerbindungHerstellen(ByVal SName As String, ByVal EName As String, ByVal UName As String, ByVal PWD As String)
              Dim sServer As String
              Dim sEntryName As String, sUsername As String, sPassword As String
              sServer = SName     'IP oder Url
              sEntryName = EName  'Verbindungsname
              sUsername = UName   '...
              sPassword = PWD     '...
              Dim re As New RASENTRY
              Dim sDeviceName As String, sDeviceType As String
              sDeviceName = "WAN(L2TP)"
              sDeviceType = "vpn"
              Dim a1(16), a2(128) As Byte
              With re
                  ReDim .szAreaCode(10)
                  ReDim .szLocalPhoneNumber(128)
                  ReDim .szDeviceName(128)
                  ReDim .szDeviceType(16)
                  ReDim .szScript(259)
                  ReDim .szAutodialDll(259)
                  ReDim .szAutodialFunc(259)
                  ReDim .szX25PadType(32)
                  ReDim .szX25Address(200)
                  ReDim .szX25Facilities(200)
                  ReDim .szX25UserData(200)
                  ReDim .szCustomDialDll(259)
                  ReDim .szDnsSuffix(255)
                  ReDim .szPrerequisitePbk(259)
                  ReDim .szPrerequisiteEntry(256)
                  .dwCountryCode = 0
                  .dwCountryID = 0
                  .dwDialExtraPercent = 75
                  .dwDialExtraSampleSeconds = 120
                  .dwDialMode = 1
                  .dwfNetProtocols = 4
                  .dwfOptions = 1024262928
                  .dwfOptions2 = 367
                  .dwFramingProtocol = 1
                  .dwHangUpExtraPercent = 10
                  .dwHangUpExtraSampleSeconds = 120
                  .dwRedialCount = 3
                  .dwRedialPause = 60
                  .dwType = RASET_Vpn '=2
                  Dim bSrc(100) As Byte
                  bSrc = System.Text.Encoding.ASCII.GetBytes(sDeviceName)
                  Dim cbCopy As Integer = sDeviceName.Length()
                  CopyMemory(.szDeviceName(0), sDeviceName, sDeviceName.Length)
                  CopyMemory(.szDeviceType(0), sDeviceType, sDeviceType.Length)
                  CopyMemory(.szLocalPhoneNumber(0), sServer, Len(sServer))
                  .dwVpnStrategy = VS_Default     '=0
                  .dwEncryptionType = ET_Optional '=3
              End With
              re.dwSize = Len(re)
              Dim rc As New RASCREDENTIALS
              With rc
                  ReDim .szPassword(256)
                  ReDim .szUserName(256)
                  ReDim .szDomain(15)
                  .dwSize = Len(rc)
                  .dwMask = 11
                  CopyMemory(.szUserName(0), sUsername, sUsername.Length)
                  CopyMemory(.szPassword(0), sPassword, sPassword.Length)
              End With
              Dim buffinfo(0) As Byte
              Dim rtn As Int32
      
              'Setzen der "Anwahlparameter" win9x und win2k
              rtn = RasSetEntryProperties(vbNullString, sEntryName, re, Len(re), 0, 0)
              rtn = 654
              'Ausgabe der Rückmeldung von RasSetEntryProperties
              MsgBox(rtn & ":" & vbCrLf & RasErrorDeclare(rtn), MsgBoxStyle.Critical, "RasSetEntryProperties")
      
              'Setzen der "Anwahlparameter" ab winXP
              rtn = RasSetCredentials(vbNullString, sEntryName, rc, 1)
              'Ausgabe der Rückmeldung von RasSetCredentials
              MsgBox(rtn & ":" & vbCrLf & RasErrorDeclare(rtn), MsgBoxStyle.Critical, "RasSetCredentials")
      
          End Sub
      Fehlermeldung/Return [rtn] ist die 632 "Die Strukturgröße ist nicht richtig."

      Die Frage ist nur warum ??

      Liegt es an der Len-Funktion ???

      Danke für Eure Hilfe ...

      Comment

      Working...
      X