Results 1 to 6 of 6

Thread: Implementing a method that can be called with WMI *dead but unresolved*

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    100

    Implementing a method that can be called with WMI *dead but unresolved*

    Here is what I have right now:

    Code:
    //Class1.cs
    
    using System;
    using System.Management;
    using System.Configuration.Install;
    using System.Management.Instrumentation;
    
    namespace WmiTest
    {
    	[System.ComponentModel.RunInstaller(true)]
    	public class MyInstaller : DefaultManagementProjectInstaller {}   
    
    	class Class1
    	{
    		//[STAThread]
    		public static int Main(string[] args) 
    		{
    			InstanceClass instClass = new InstanceClass();
    			instClass.Name = "Hello World 01";
    			instClass.Number = 1;
    
    			Instrumentation.Publish(instClass);        
    
    			InstanceClass instClass2 = new InstanceClass();
    			instClass2.Name = "Hello World 02";
    			instClass2.Number = 2;
    
    			Instrumentation.Publish(instClass);        
    			Instrumentation.Publish(instClass2);        
    
    			Console.WriteLine("Instance now visible through WMI");
    			Console.ReadLine();
    			Instrumentation.Revoke(instClass); //optional
    			Instrumentation.Revoke(instClass2); //optional
    			
    			return 0;
    		}
    	}
    
    
    	[InstrumentationClass(InstrumentationType.Instance)]
    	public class InstanceClass 
    	{
    		public string Name = "";
    		public int Number = 0;
    
    		public void TestMethod()
    		{
    			Console.WriteLine("asdf");
    		}
    	}
    Code:
    //AssemblyInfo.cs
    //This also was added to this file.
    
    using System.Management.Instrumentation;
    
    [assembly:Instrumented("root/test")]

    I'm trying to call the method TestMethod from a wmi script and it says it doesn't exist, however I can access the Name or Number properties!


    Here is my wmi script:

    Code:
    ' put this code in a file with an extension .vbs to run it
    set wmi = GetObject("winmgmts:root/test")
    
    wql = "SELECT * from InstanceClass"
    set result = wmi.ExecQuery(wql)
    
    For Each instance in result
    	MsgBox instance.Name & ": " & instance.Number
    	instance.TestMethod
    Next

    Thanks guys,
    Mitchel
    Last edited by toto; Oct 10th, 2003 at 12:10 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    100
    *bump*

    I really need help with this!

    Thanks again guys,
    Mitchel

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What's WMI?

    Maybe you need some attribute on the function too?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Try giving it a different name using ManagedNameAttribute, maybe it finds it by that name.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    100
    WMI is Windows Management Instrumentation it's something windows software implements for simple management. IIS uses it and with a simple script you can add and remove IIS websites for example without using a DLL.

    I'll look into that attribute.. thanks.

    Mitchel

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    100
    * one last bump * =)

    If it isn't possible I guess I'll just have to give up on it.

    Thanks anyways guys,
    Mitchel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width