我们正在尝试为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技能,我承认我很难解决。任何帮助都将深表感谢!
答案 0 :(得分:0)
我自己在论坛中使用AutoIT UDF解决了这个问题。 UDF调用wlanapi.dll并允许使用其功能来配置WLAN访问,配置文件等。
Windows 7的步骤是:
Windows 8的步骤是:
希望这有帮助