MSCluster_Resource.CreateResource problem

  • Thread starter Thread starter Jean-Francois Hamelin
  • Start date Start date
J

Jean-Francois Hamelin

Hi,

I'm trying to create a cluster resource and setting the parameters for a
Generic Service resource type using System.Management classes.

Invoking the method CreateResource works fine, but setting the
PrivatesProperties and then saving the changes generates a the following
exception when calling Put:

System.IO.FileNotFoundException was unhandled
Message="The filename, directory name, or volume label syntax is
incorrect.\r\n"
Source="WinMgmt"
StackTrace:
at
System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32
errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32
errorCode)
at System.Management.ManagementObject.Put(PutOptions options)
at System.Management.ManagementObject.Put()

My code:

ManagementClass resource_Class = new
ManagementClass("\\\\.\\root\\MSCluster:MSCluster_Resource");
ManagementBaseObject inParams = null;

inParams = resource_Class.GetMethodParameters("CreateResource");
inParams["Group"] = ((System.String)("MyGroup"));
inParams["ResourceName"] = ((System.String)("MyResourceName"));
inParams["ResourceType"] = ((System.String)("Generic Service"));
inParams["SeparateMonitor"] = ((System.Boolean )(false));
resource_Class.InvokeMethod("CreateResource", inParams, null);

ManagementObject resource_Object = new
ManagementObject("\\\\.\\root\\MSCluster:MSCluster_Resource.Name=\"MyResourceName\"");
resource_Object.Get();

ManagementBaseObject property_Generic_Service_Object =
resource_Object["PrivateProperties"] as ManagementBaseObject;
property_Generic_Service_Object["ServiceName"] =
((System.String)("MyWin32ServiceName"));
property_Generic_Service_Object["StartupParameters"] =
((System.String)("MyParameters"));
property_Generic_Service_Object["UseNetworkName"] =
((System.UInt32)(1));

resource_Object.Put(); <== Throws
System.IO.FileNotFoundException

Thanks in advance
JF
 
Adding:

"resource_Object.SetPropertyValue("PrivateProperties", property_Generic_Service_Object); "

before calling:

"resource_Object.Put();"

should do the trick.

I know this post comes late but it should help other users that get stuck in setting these properties.
 
Back
Top