INetSharingConfiguration-> EnableSharing (ICSSHARINGTYPE_PUBLIC) returns 0x80040201

I am trying to programmatically allow sharing to a public type of sharing 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 error list shows the following: E_ABORT, E_FAIL, E_INVALIDARG, E_NOINTERFACE, E_NOTIMPL, E_OUTOFMEMORY, E_POINTER and E_UNEXPECTED.

The error code that I return is 0x80040201, which resolves: "The event failed to call any of the subscribers." which does not seem to match any of the above error codes.

If I manually go into the properties of network adapters and go to the sharing tab and enable sharing and select a private network and click "OK", sharing will be enabled.

After that, my above code works without problems.

I can even manually set up sharing with another adapter (public) and another private network, and then run my code and see that my code updates the public and private networks to what I want. This seems to work only after sharing is first allowed manually through the network properties panel.

The problem is duplicated on two different computers running Windows 7 64 bit. It seems like after removing the network adapter driver from the system when sharing is enabled on it, then reinstall the network adapter driver.

I tried to disable the uninstaller when uninstalling, but it seems successful or missed.

The Windows network sharing properties panel does something behind the scenes that this API call does not, because it manually configures the sharing on the adapter.

Does anyone have any idea what this might be?

+6
source share
1 answer

I had the same problem in Windows 8.1 and ended up fixing it after reading it: https://support.microsoft.com/kb/828807

My code is C #, but I'm sure you can do the same 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; } } } 
+1
source

Source: https://habr.com/ru/post/912890/


All Articles