WMI

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 ...
 
W

Willy Denoyette [MVP]

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.
 
G

Guest

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.
 
W

Willy Denoyette [MVP]

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.
 
G

Guest

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.
 
W

Willy Denoyette [MVP]

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.
 
G

Guest

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.
 
W

Willy Denoyette [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top