Results 1 to 6 of 6

Thread: CreateProcess WMI C#

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    CreateProcess WMI C#

    back again with another question.
    I want to remotely create and run a process on that remote computer using WMI. I am having problems but getting closer I believe

    Error when trying to invoke method:

    "Operation is not valid due to the current state of the object"

    Code:
    ManagementPath thePath = new ManagementPath("\\\\server\\root\\cimv2");
    ManagementClass theClass = new ManagementClass(thePath);
    theClass.InvokeMethod("Create", new object[] { "Calc.exe" });
    any ideas?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: CreateProcess WMI C#

    I would suggest that you use the MgmtClassGen.exe utility to generate a .NET class that corresponds to the WMI class you want to use. That way you will be using objects of the appropriate type and calling methods directly instead of using things like InvokeMethod. That way you'll get Intellisense too.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: CreateProcess WMI C#

    Thank you. I do appreciate this however for now is it possible to find out what the error actually means and get to the root of the problem?
    ill look into the suggested tool however it would be nice to find out how to resolve the error as it stands, apart from using this tool,

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: CreateProcess WMI C#

    PS - the above code does work fine locally but not on the remote computer. locally running WS2003 SP1 and on the other one Windows 2000 PRO SP4

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: CreateProcess WMI C#

    got it!

    ManagementClass should be constructed with this string:

    "\\\\server\\root\\cimv2:Win32_Process"

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  6. #6
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: CreateProcess WMI C#

    and oh instead of using \ for escape character use @.

    i.e @\\server\root\cimv2

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