title: Enabling filestream with WMI and C#
body: <p>I have need to enable FILESTREAM on a SQL Server through a program.  According to documentation I have found, this can be done through WMI with the following code:</p>
  
  <pre><code>set fsInstance = GetObject("WINMGMTS:\\" &amp; MachineName &amp; "\root\Microsoft\SqlServer\ComputerManagement10:FilestreamSettings='" &amp; InstanceName &amp; "'")
  Set method = fsInstance.Methods_("EnableFilestream")
  Set inParam = method.inParameters.SpawnInstance_()
  inParam.AccessLevel = TargetLevel
  inParam.ShareName = ShareName
  Set outParam = fsInstance.ExecMethod_("EnableFilestream", inParam)
  </code></pre>
  
  <p>Converting this to C#, I get the following:</p>
  
  <pre><code>ManagementClass mc = new ManagementClass(new ManagementScope(@"\\.\root\Microsoft\SqlServer\ComputerManagement10"), 
                  new ManagementPath("FilestreamSettings"), 
                  new ObjectGetOptions(new ManagementNamedValueCollection() {
                      {"InstanceName", "MSSQLSERVER"}
              }));
  ManagementBaseObject inParams = mc.GetMethodParameters("EnableFilestream");
  inParams["AccessLevel"] = 1;
  inParams["ShareName"] = "ALLIANCE";
  mc.InvokeMethod("EnableFilestream", inParams, null);
  </code></pre>
  
  <p>Whenever I try this, though, it throws an exception on InvokeMethod.  The message is "Invalid method parameter(s)".  I have attempted to remove the two lines where I set AccessLevel and ShareName and run it that way, but get the same exception.  What am I doing wrong here?</p>