WMI

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
sorry for my bad Englisch.How I create new instance ? I try :
ManagementPath pt = new ManagementPath();
pt.NamespacePath = "root\\cimv2";
pt.ClassName = "Win32_Process";
ManagementClass mc = new ManagementClass(pt);
ManagementObject mo = mc.CreateInstance();
mo["CommandLine"]="c:\\windows\\system32\\notepad.exe";
mo.Put();
but this not work ...
 
Marek G said:
Hi all,
sorry for my bad Englisch.How I create new instance ? I try :
ManagementPath pt = new ManagementPath();
pt.NamespacePath = "root\\cimv2";
pt.ClassName = "Win32_Process";
ManagementClass mc = new ManagementClass(pt);
ManagementObject mo = mc.CreateInstance();
mo["CommandLine"]="c:\\windows\\system32\\notepad.exe";
mo.Put();
but this not work ...

You can't create an instance that way, you have to invoke the "Create"
method of the Win32_Process class. I'm not clear why you want to use WMI,
why not simply use "System.Diagnostics.Process.Start()" for this?

Willy.
 
Why I use CreateInstance and Create ?
ManagementClass envClass = new ManagementClass("Win32_Environment");
ManagementObject newInstance =
existingClass.CreateInstance("My_Service");
newInstance["Name"] = "Cori";
newInstance.Put(); //to commit the new instance.

???



Willy Denoyette said:
Marek G said:
Hi all,
sorry for my bad Englisch.How I create new instance ? I try :
ManagementPath pt = new ManagementPath();
pt.NamespacePath = "root\\cimv2";
pt.ClassName = "Win32_Process";
ManagementClass mc = new ManagementClass(pt);
ManagementObject mo = mc.CreateInstance();
mo["CommandLine"]="c:\\windows\\system32\\notepad.exe";
mo.Put();
but this not work ...

You can't create an instance that way, you have to invoke the "Create"
method of the Win32_Process class. I'm not clear why you want to use WMI,
why not simply use "System.Diagnostics.Process.Start()" for this?

Willy.
 
You can't create instances of WMI objects, you have to create the process
using "create" method, WMI will automatically create an instance in the
metabase.

Something like this will do:

ManagementPath path = new ManagementPath( "Win32_Process");
//Get the object on which the method will be invoked
ManagementClass processClass = new ManagementClass(path);
//Create an array containing all arguments for the method
object[] methodArgs = {"notepad.exe", null, null, 0};

//Execute the method
processClass.InvokeMethod ("Create", methodArgs);

Willy.

Marek G said:
Why I use CreateInstance and Create ?
ManagementClass envClass = new ManagementClass("Win32_Environment");
ManagementObject newInstance =
existingClass.CreateInstance("My_Service");
newInstance["Name"] = "Cori";
newInstance.Put(); //to commit the new instance.

???



Willy Denoyette said:
Marek G said:
Hi all,
sorry for my bad Englisch.How I create new instance ? I try :
ManagementPath pt = new ManagementPath();
pt.NamespacePath = "root\\cimv2";
pt.ClassName = "Win32_Process";
ManagementClass mc = new ManagementClass(pt);
ManagementObject mo = mc.CreateInstance();
mo["CommandLine"]="c:\\windows\\system32\\notepad.exe";
mo.Put();
but this not work ...

You can't create an instance that way, you have to invoke the "Create"
method of the Win32_Process class. I'm not clear why you want to use WMI,
why not simply use "System.Diagnostics.Process.Start()" for this?

Willy.
 
and preview exampl is from msdn....


ManagementClass envClass = new ManagementClass("Win32_Environment");
ManagementObject newInstance =
existingClass.CreateInstance("My_Service");
newInstance["Name"] = "Cori";
newInstance.Put(); //to commit the new instance.

Willy Denoyette said:
You can't create instances of WMI objects, you have to create the process
using "create" method, WMI will automatically create an instance in the
metabase.

Something like this will do:

ManagementPath path = new ManagementPath( "Win32_Process");
//Get the object on which the method will be invoked
ManagementClass processClass = new ManagementClass(path);
//Create an array containing all arguments for the method
object[] methodArgs = {"notepad.exe", null, null, 0};

//Execute the method
processClass.InvokeMethod ("Create", methodArgs);

Willy.

Marek G said:
Why I use CreateInstance and Create ?
ManagementClass envClass = new ManagementClass("Win32_Environment");
ManagementObject newInstance =
existingClass.CreateInstance("My_Service");
newInstance["Name"] = "Cori";
newInstance.Put(); //to commit the new instance.

???



Willy Denoyette said:
Hi all,
sorry for my bad Englisch.How I create new instance ? I try :
ManagementPath pt = new ManagementPath();
pt.NamespacePath = "root\\cimv2";
pt.ClassName = "Win32_Process";
ManagementClass mc = new ManagementClass(pt);
ManagementObject mo = mc.CreateInstance();
mo["CommandLine"]="c:\\windows\\system32\\notepad.exe";
mo.Put();
but this not work ...

You can't create an instance that way, you have to invoke the "Create"
method of the Win32_Process class. I'm not clear why you want to use WMI,
why not simply use "System.Diagnostics.Process.Start()" for this?

Willy.
 
Marek G said:
and preview exampl is from msdn....

Not sure what you mean with this.

Willy.

ManagementClass envClass = new ManagementClass("Win32_Environment");
ManagementObject newInstance =
existingClass.CreateInstance("My_Service");
newInstance["Name"] = "Cori";
newInstance.Put(); //to commit the new instance.

Willy Denoyette said:
You can't create instances of WMI objects, you have to create the process
using "create" method, WMI will automatically create an instance in the
metabase.

Something like this will do:

ManagementPath path = new ManagementPath( "Win32_Process");
//Get the object on which the method will be invoked
ManagementClass processClass = new ManagementClass(path);
//Create an array containing all arguments for the method
object[] methodArgs = {"notepad.exe", null, null, 0};

//Execute the method
processClass.InvokeMethod ("Create", methodArgs);

Willy.

Marek G said:
Why I use CreateInstance and Create ?
ManagementClass envClass = new ManagementClass("Win32_Environment");
ManagementObject newInstance =
existingClass.CreateInstance("My_Service");
newInstance["Name"] = "Cori";
newInstance.Put(); //to commit the new instance.

???



:


Hi all,
sorry for my bad Englisch.How I create new instance ? I try :
ManagementPath pt = new ManagementPath();
pt.NamespacePath = "root\\cimv2";
pt.ClassName = "Win32_Process";
ManagementClass mc = new ManagementClass(pt);
ManagementObject mo = mc.CreateInstance();
mo["CommandLine"]="c:\\windows\\system32\\notepad.exe";
mo.Put();
but this not work ...

You can't create an instance that way, you have to invoke the "Create"
method of the Win32_Process class. I'm not clear why you want to use
WMI,
why not simply use "System.Diagnostics.Process.Start()" for this?

Willy.
 
I mind :
Why Microsoft sometime use Create to create instance . etc service a and
sometime I must call method create ....

Willy Denoyette said:
Marek G said:
and preview exampl is from msdn....

Not sure what you mean with this.

Willy.

ManagementClass envClass = new ManagementClass("Win32_Environment");
ManagementObject newInstance =
existingClass.CreateInstance("My_Service");
newInstance["Name"] = "Cori";
newInstance.Put(); //to commit the new instance.

Willy Denoyette said:
You can't create instances of WMI objects, you have to create the process
using "create" method, WMI will automatically create an instance in the
metabase.

Something like this will do:

ManagementPath path = new ManagementPath( "Win32_Process");
//Get the object on which the method will be invoked
ManagementClass processClass = new ManagementClass(path);
//Create an array containing all arguments for the method
object[] methodArgs = {"notepad.exe", null, null, 0};

//Execute the method
processClass.InvokeMethod ("Create", methodArgs);

Willy.

Why I use CreateInstance and Create ?
ManagementClass envClass = new ManagementClass("Win32_Environment");
ManagementObject newInstance =
existingClass.CreateInstance("My_Service");
newInstance["Name"] = "Cori";
newInstance.Put(); //to commit the new instance.

???



:


Hi all,
sorry for my bad Englisch.How I create new instance ? I try :
ManagementPath pt = new ManagementPath();
pt.NamespacePath = "root\\cimv2";
pt.ClassName = "Win32_Process";
ManagementClass mc = new ManagementClass(pt);
ManagementObject mo = mc.CreateInstance();
mo["CommandLine"]="c:\\windows\\system32\\notepad.exe";
mo.Put();
but this not work ...

You can't create an instance that way, you have to invoke the "Create"
method of the Win32_Process class. I'm not clear why you want to use
WMI,
why not simply use "System.Diagnostics.Process.Start()" for this?

Willy.
 
Marek G said:
I mind :
Why Microsoft sometime use Create to create instance . etc service a and
sometime I must call method create ....
The create method is used to create the process, that is start the program.
When the program has started WMI will automatically create an instance of
the WMI class. You cannot create an instance of a class yourself without
starting the program.
You seems to be missing a fundamental understanding of WMI, therefore I
would suggest you take a look at the WMI platfor SDK.

Willy.
Marek G said:
and preview exampl is from msdn....

Not sure what you mean with this.

Willy.

ManagementClass envClass = new ManagementClass("Win32_Environment");
ManagementObject newInstance =
existingClass.CreateInstance("My_Service");
newInstance["Name"] = "Cori";
newInstance.Put(); //to commit the new instance.

:

You can't create instances of WMI objects, you have to create the
process
using "create" method, WMI will automatically create an instance in
the
metabase.

Something like this will do:

ManagementPath path = new ManagementPath( "Win32_Process");
//Get the object on which the method will be invoked
ManagementClass processClass = new ManagementClass(path);
//Create an array containing all arguments for the method
object[] methodArgs = {"notepad.exe", null, null, 0};

//Execute the method
processClass.InvokeMethod ("Create", methodArgs);

Willy.

Why I use CreateInstance and Create ?
ManagementClass envClass = new ManagementClass("Win32_Environment");
ManagementObject newInstance =
existingClass.CreateInstance("My_Service");
newInstance["Name"] = "Cori";
newInstance.Put(); //to commit the new instance.

???



:


Hi all,
sorry for my bad Englisch.How I create new instance ? I try :
ManagementPath pt = new ManagementPath();
pt.NamespacePath = "root\\cimv2";
pt.ClassName = "Win32_Process";
ManagementClass mc = new ManagementClass(pt);
ManagementObject mo = mc.CreateInstance();
mo["CommandLine"]="c:\\windows\\system32\\notepad.exe";
mo.Put();
but this not work ...

You can't create an instance that way, you have to invoke the
"Create"
method of the Win32_Process class. I'm not clear why you want to
use
WMI,
why not simply use "System.Diagnostics.Process.Start()" for this?

Willy.
 
Back
Top