摘要:使用C#設定無線網路
之前曾經用過的wlanapi.dll, 是用來設定無線網路
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct WLAN_CONNECTION_PARAMETERS
{
public UInt32 wlanConnectionMode;
[MarshalAs(UnmanagedType.LPTStr)]
public String strProfile;
public IntPtr pDot11Ssid;
public IntPtr pDesiredBssidList;
public UInt32 dot11BssType;
public UInt32 dwFlags;
}
[DllImport("wlanapi.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
private static extern UInt32 WlanOpenHandle(UInt32 dwClientVersion, IntPtr pReserved, ref UInt32 pdwNegotiatedVersion, ref IntPtr phClientHandle);
[DllImport("wlanapi.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
private static extern UInt32 WlanCloseHandle(IntPtr hClientHandle, IntPtr pReserved);
[DllImport("wlanapi.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
private static extern UInt32 WlanSetProfile(IntPtr hClientHandle, ref Guid pInterfaceGuid, UInt32 dwFlags, String strProfileXml, String strAllUserProfileSecurity, bool bOverwrite, IntPtr pReserved, ref UInt32 pdwReasonCode);
[DllImport("wlanapi.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
private static extern UInt32 WlanDeleteProfile(IntPtr hClientHandle, ref Guid pInterfaceGuid, String strProfileName, IntPtr pReserved);
[DllImport("wlanapi.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
private static extern UInt32 WlanConnect(IntPtr hClientHandle, ref Guid pInterfaceGuid, ref WLAN_CONNECTION_PARAMETERS pConnectionParameters, IntPtr pReserved);