我们正在尝试为 BYOD 用户创建一个应用程序,以便他们轻松连接到我们的 802.1x 网络。
我在网上找到了以下代码:
Imports System.Runtime.InteropServices
Module Module1
Private _stringToHex As Object
Private Property Ret As UInteger
Private Property StringToHex(profileName As String) As Object
Get
Return _stringToHex
End Get
Set(value As Object)
_stringToHex = value
End Set
End Property
Private Property handle As IntPtr
Private Property Guid As Guid
<DllImport("Wlanapi", EntryPoint:="WlanSetProfileEapXmlUserData")> _
Public Function WlanSetProfileEapXmlUserData(<[In]()> ByVal hClientHandle As IntPtr, _
<[In](), MarshalAs(UnmanagedType.LPStruct)> ByVal interfaceGuid As Guid, _
<[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal strProfileName As String, _
<[In]()> ByVal flags As ULong, _
<[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal profileXml As String, _
<[In]()> ByVal pReserved As IntPtr) As UInteger
End Function
Sub Main()
Dim profileName As String = "ISL"
Dim AuthXml As String = String.Format("<?xml version=""1.0"" ?>" & _
"<EapHostUserCredentials xmlns=""http://www.microsoft.com/provisioning/EapHostUserCredentials"" xmlns:eapCommon=""http://www.microsoft.com/provisioning/EapCommon"" xmlns:baseEap=""http://www.microsoft.com/provisioning/BaseEapMethodUserCredentials"">" & _
"<EapMethod>" & _
"<eapCommon:Type>25</eapCommon:Type>" & _
"<eapCommon:AuthorId>0</eapCommon:AuthorId>" & _
"</EapMethod>" & _
"<Credentials xmlns:eapUser=""http://www.microsoft.com/provisioning/EapUserPropertiesV1"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:baseEap=""http://www.microsoft.com/provisioning/BaseEapUserPropertiesV1"" xmlns:MsPeap=""http://www.microsoft.com/provisioning/MsPeapUserPropertiesV1"" xmlns:MsChapV2=""http://www.microsoft.com/provisioning/MsChapV2UserPropertiesV1"">" & _
"<baseEap:Eap>" & _
"<baseEap:Type>25</baseEap:Type>" & _
"<MsPeap:EapType>" & _
"<MsPeap:RoutingIdentity>username</MsPeap:RoutingIdentity>" & _
"<baseEap:Eap>" & _
"<baseEap:Type>26</baseEap:Type>" & _
"<MsChapV2:EapType>" & _
"<MsChapV2:Username>USERNAME</MsChapV2:Username>" & _
"<MsChapV2:Password>PASSWORD</MsChapV2:Password>" & _
"<MsChapV2:LogonDomain>DOMAIN</MsChapV2:LogonDomain>" & _
"</MsChapV2:EapType>" & _
"</baseEap:Eap>" & _
"</MsPeap:EapType>" & _
"</baseEap:Eap>" & _
"</Credentials>" & _
"</EapHostUserCredentials>", profileName, StringToHex(profileName))
Ret = WlanSetProfileEapXmlUserData(handle, Guid, profileName, Convert.ToUInt64(&H1), AuthXml, IntPtr.Zero)
End Sub
End Module
这给了我以下错误:“附加信息:对 PInvoke 函数 'test_wlan_conf!test_wlan_conf.Module1::WlanSetProfileEapXmlUserData' 的调用使堆栈不平衡。这可能是因为托管 PInvoke 签名与非托管目标签名不匹配。检查PInvoke 签名的调用约定和参数与目标非托管签名匹配。”
凭借我几乎不存在的 .net 技能,我承认这对我来说真的很难解决。任何帮助将不胜感激!