I am trying to programmatically enable sharing with the sharing type public on a device that matches a known GUID on a windows 7 machine.
API at: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365944(v=vs.85).aspx
The list of errors show the following: E_ABORT, E_FAIL, E_INVALIDARG, E_NOINTERFACE, E_NOTIMPL, E_OUTOFMEMORY, E_POINTER, and E_UNEXPECTED.
The error code I am getting back is 0x80040201 which resolves to: "An event was unable to invoke any of the subscribers." which doesn't seem to match any of the above listed error codes.
If I manually go into the network adapters properties and go to the sharing tab and enable sharing and select the private network and click ok, sharing gets enabled properly.
After this my above code runs without issue.
I can even manually set sharing on another adapter (public) and a different private network and then run my code and see that my code updates the public and private networks to what I want. This only seems to work after first manually enabling sharing through the network properties pane.
The issue has been duplicated on two different computer running windows 7 64 bit. It seems to happen after uninstalling the network adapter driver from the system when sharing is enabled on it and then re-installing the network adapter driver.
I've tried making the uninstaller disable sharing during uninstall but this seems to be hit or miss.
The windows network sharing property pane is doing something behind the scenes that this API call does not do since manually setting sharing on the adapter works every time.
Does anyone have any ideas what that might be?
I had the same issue on windows 8.1 and ended up fixing it after reading:https://support.microsoft.com/kb/828807
My code is C# but I´m sure you can do the same thing in C++
// Disable ICS on any network iterfaces which may no longer be present in the system
public void Disable_ICS_WMI()
{
ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\Microsoft\\HomeNet");
//create object query
ObjectQuery query = new ObjectQuery("SELECT * FROM HNet_ConnectionProperties ");
//create object searcher
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
//get a collection of WMI objects
ManagementObjectCollection queryCollection = searcher.Get();
//enumerate the collection.
foreach (ManagementObject m in queryCollection)
{
// access properties of the WMI object
Console.WriteLine("Connection : {0}", m["Connection"]);
try
{
PropertyDataCollection properties = m.Properties;
foreach(PropertyData prop in properties)
{
if (prop.Name == "IsIcsPrivate" && ((Boolean) prop.Value ) == true)
{
prop.Value = false;
m.Put();
}
}
} catch (Exception e)
{
Console.WriteLine("ex " + e.Message);
continue;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With