ObjectGetOptions options = new ObjectGetOptions();
ManagementPath p = new ManagementPath("\\\\server01\\root" + "\\cimv2:Win32_Share");
// Make a connection to a remote computer.
ManagementScope scope = new ManagementScope("\\\\server01\\root\\cimv2");
scope.Connect();
// Create a ManagementClass object
ManagementClass managementClass = new ManagementClass(scope, p, options);
// Create ManagementBaseObjects for in and out parameters
ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
ManagementBaseObject outParams;
// Set the input parameters
//inParams["Description"] = String.Empty;
inParams["Name"] = "test";
inParams["Path"] = @folderPath;
inParams["Type"] = 0x0; // Disk Drive
// Invoke the method on the ManagementClass object
outParams = managementClass.InvokeMethod("Create", inParams, null);
// Check to see if the method invocation was successful
if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
{
throw new Exception("Unable to share directory. Error code: " + outParams.Properties["ReturnValue"].Value);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString());
}
}
次のコードを使用して共有を設定していますが、名前が無効であることを意味する戻り値9が常に表示されます。文字列を渡していますが、明示的な文字列を使用しようとしましたが、エラー9が発生します。
ただし、ローカルマシンではなく、リモートで共有を作成しています。リモートWMIプロバイダーに接続していることを確認しようとしましたが、成功したかどうかはわかりません。
WMIの達人や他の人からの提案は大歓迎です。