SYMPTOMS
When you use a custom program to programmatically remove and then reinstall Internet Connection Sharing on a computer that has more than one network adapter, you may receive the following error message:
An event was unable to invoke any of the subscribers. Code: 80040201
WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
The following code is not a substitute for the
DisableSharing and
EnableSharing methods. The following code is just a workaround to use those methods when an exceptional condition (such as the NIC no longer being present) occurs.
In your code, call
DisableSharing before you call
EnableSharing. If you receive the 80040201 error while you are calling
EnableSharing for the private interface, the error should be caught and you can use the following sample code to recover from it. The sample code is written in VBScript. However, you can use any language that can access Windows Management Instrumentation (WMI) to complete these steps:
Set Service = GetObject("winmgmts:{impersonationLevel=impersonate}!root/Microsoft/HomeNet")
Set enumset = Service.InstancesOf("HNet_ConnectionProperties")
for each Instance in enumSet
if Instance.IsIcsPrivate = true then
Instance.IsIcsPrivate = false
Instance.put_()
end if
Next
After you run this code, call
DisableSharing before you start over with the
EnableSharing method.
If you receive the 80040201 error while calling
EnableSharing for the public interface, run the code again, except replace IsIcsPrivate with IsIcsPublic. Call
DisableSharing again before you start over with the
EnableSharing method.
The
EnableSharing and
DisableSharing methods do more than just toggle the two flags that this article mentions. If the process of enabling sharing is interrupted, you must call
DisableSharing be called before you start over.