title: COM Object behaving differently in ASP Classic and VBscript
body: <p>----- this issue was solved, doesn't relate to subject see explanation at bottom -----</p>
  
  <p>I've put together a C# dll that I'm running as a COM object to handle Exchange Server processing.  One of functions it performs creates a users mailbox.  I've set up a COM+ application so it's running as an Exchange Administrator.</p>
  
  <p>When CreateObject in VBScript and call the function, it works.  When I do the same thing in an ASP page (using Server.CreateObject) it does nothing.</p>
  
  <p>Any ideas as to what different behaviors I should be looking for between VBscript and ASP Classic in this case?</p>
  
  <p>The DLL code being executed:</p>
  
  <pre><code>public void CreateMailbox(String database, String dc, String upn)
  {
      String retval = String.Empty;
      Dictionary&lt;String, object&gt; args = new Dictionary&lt;string, object&gt;();
      args.Add("Identity", upn);
      args.Add("Database", database);
      args.Add("DomainController", dc);            
      Collection&lt;PSObject&gt; result = ExecuteCmdlet("Enable-Mailbox", args);
      return;
  }
  </code></pre>
  
  <p>And ExecuteCmdlet</p>
  
  <pre><code>private Collection&lt;PSObject&gt; ExecuteCmdlet(String cmdlet, Dictionary&lt;String,object&gt; arguments)
  {
      RunspaceConfiguration rsConf = RunspaceConfiguration.Create();
      PSSnapInException psException = null;
      PSSnapInInfo psInfo = rsConf.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out psException);
      Runspace rs = RunspaceFactory.CreateRunspace(rsConf);
      rs.Open();
      Pipeline pipe = rs.CreatePipeline();
      Command psCmd = new Command(cmdlet);
      foreach (KeyValuePair&lt;String,object&gt; arg in arguments)
      {
          psCmd.Parameters.Add(arg.Key, arg.Value);
      }
      pipe.Commands.Add(psCmd);
      Collection&lt;PSObject&gt; retVal = pipe.Invoke();
      rs.Close();
      return retVal;
  }
  </code></pre>
  
  <p>EDIT: This seems to be an issue with my ASP implementation, which involves me trying to tie it into a 3rd party AD management tool.  When I use the code in a stand alone ASP page, it works.  Seems like this requires some more research on my part.</p>
  
  <p>EDIT2: A couple hours of research hasn't yielded anything on the way IIS handles COM+ objects that have a bound identity in any way indicating the problem.  The VBS requested is below.  This works.  This exact same code works in an ASP Classic web page.  When I run this exact same code in a different web app in the same vdir, it fails to create the mailbox.  The app in question is a MVC front end to Active Directory written in ASP Classic.</p>
  
  <pre><code>Dim exch
  Set exch = CreateObject("ExchangeMailboxCreator.ExchangeMailboxBuilder")
  exch.CreateMailbox("Mailbox\SG\DB", "domaincontroller.domain.com", "TestUserAccount")
  </code></pre>
  
  <p>FINAL EDIT: Unsurprisingly, this was an issue not with the above code, but with the code around it.  The application I was integrating with was using AD LDS as a staging directory before periodically writing back to AD.  This meant my attempts to directly touch Exchange were failing because the AD account didn't exist.  I hacked my way around it by adding a loop to sleep until the Exchange environment recognized the user existed.  Not... my favorite solution ever, but I'll take it.  Thanks for all the suggestions.</p>