title: Creating a COM Callable Wrapper For System.Net.NetworkInformation.Ping
body: <p>I'm working on creating a COM callable wrapper for the System.Net.NetworkInformation.Ping class for use in WSH scripts. I've gotten it to compile, but it's not working when called from WSH. I'm not very familiar with COM, so please forgive me if the error is obvious.</p>
  
  <p>Here is the code in my assembly:</p>
  
  <pre><code>using System;
  using System.Reflection;
  using System.Runtime.InteropServices;
  using System.Net;
  using System.Net.NetworkInformation;
  
  
  [assembly: AssemblyVersion("0.0.1.0")]
  
  namespace net.digital_traffic.interop.wrapper
  {
  [ComVisible(true)]
  public interface IPing
  {
      //void OnPingCompleted(PingCompletedEventArgs e);
      PingReply Send(IPAddress address);
      PingReply Send(String hostNameOrAddress);
      PingReply Send(IPAddress address, Int32 timeout);
      PingReply Send(String hostNameOrAddress, Int32 timeout);
      PingReply Send(IPAddress address, Int32 timeout, Byte[] buffer);
      PingReply Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer);
      PingReply Send(IPAddress hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options);
      PingReply Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options);
      /*
      void SendAsync(IPAddress address, Object userToken);
      void SendAsync(String hostNameOrAddress, Object userToken);
      void SendAsync(IPAddress address, Int32 timeout, Object userToken);
      void SendAsync(String hostNameOrAddress, Int32  timeout, Object userToken);
      void SendAsync(IPAddress address, Int32 timeout, Byte[] buffer, Object userToken);
      void SendAsync(String hostNameOrAddress, Int32 timeout, Byte[] buffer, Object userToken);
      void SendAsync(IPAddress address, Int32 timeout, Byte[] buffer, PingOptions options, Object userToken);
      void SendAsync(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options, Object userToken);
      void SendAsyncCancel();
      */
  }
  
  [ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
  public class Ping : System.Net.NetworkInformation.Ping, IPing
  {
      public Ping() : base() { }
  }
  
  }
  </code></pre>
  
  <p>Here is the code I'm using to call the assembly in WSH:</p>
  
  <pre><code>var ping1 = new ActiveXObject("net.digital_traffic.interop.wrapper.Ping");
  
  WScript.Echo(ping1.Send("127.0.0.1"));
  </code></pre>
  
  <p>The above gives me "'ping1' is null or not an object".</p>