I’ve got an app that needs to disable infrastructure access and then re-enable it (please don’t ask why. I’m under NDA and it would be hard to explain why without violating that). I’m doing this with p/Invoke in C#.
To disable it, I’m creating the INTF_ENTRY structure, setting the adapter guid, then setting dwCtlFlags to 0 and calling
uint outFlags;
WZCSAPI.INTF_ENTRY intf = new WZCSAPI.INTF_ENTRY();
intf.wszGuid = adapterGuid;
intf.dwCtlFlags = 0;
WZCSetInterface(null, (uint)INTF_FLAGS.INTF_CM_MASK, ref intf, out outFlags)
This works beautifully and does exactly what I expect. My XP settings under “Wireless Network Connection Properties/Wireless Networks/Advanced” switches from “Any available network (access point preferred)” to “Computer-to-computer (ad hoc) networks only”. This is exactly what I need it to do…
Before doing this, I retrieve the original settings for the CM_MASK.
So, later on, I try the same thing to restore it (in this case, origCMMask = 2):
uint outFlags;
WZCSAPI.INTF_ENTRY intf = new WZCSAPI.INTF_ENTRY();
intf.wszGuid = adapterGuid;
intf.dwCtlFlags = origCMMask;
WZCSetInterface(null, (uint)INTF_FLAGS.INTF_CM_MASK, ref intf, out outFlags)
But the “Any Available Network” option is not restored in the settings dialog and the HKLM\SOFTWARE\Microsoft\WZCSVC\Parameters\Interface{guid}\ControlFlags concurs that the CM Mask is NOT set back to 2, but is still set to 0 (actual value is 0x07918000, instead of the normal 0x07818002).
Is there some step I’m missing?
You could try with the WlanSetInterface Function, if you have Windows XP with SP3, passing
wlan_intf_opcode_bss_typeas the OpCode.Alternatively, you can also try manually with one of the NETSH WLAN command line actions, at least to validate the approach.