Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. WMI Win32_Process

WMI Win32_Process

Scheduled Pinned Locked Moved C#
questiondatabasehelptutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    skrishnasarma
    wrote on last edited by
    #1

    Hi I am having small problem in WMI related question. The folowing function will accept username,password and process executable path as input parameter, and it will launch a new process in the host.and finally I will fetch Process ID and process name. This code is working fine for the current user, that means passing username and password as null. My requrement is I wand to run a process for a different user( with username and password) Can any one guide me in this rehgard? void LaunchProcess(string filename,string username,string password) { bool currentUser = false; string processName = ""; uint processID = 0; if( (username != null)&& (password != null)) currentUser = true; // LaunchProcess got username and Password. ConnectionOptions objConnectionOptions = new ConnectionOptions(); if(currentUser ==true) { objConnectionOptions.Username = username; objConnectionOptions.Password = password; } ManagementScope objManagementScope = new ManagementScope("root\\cimv2", objConnectionOptions); objManagementScope.Connect(); ManagementClass processClass = new ManagementClass("Win32_Process"); processClass.Scope = objManagementScope; //Get an input parameters object for this method ManagementBaseObject inParams = processClass.GetMethodParameters("Create"); //Fill in input parameter values inParams["CommandLine"] = filename; // this will execute the command. ManagementBaseObject outParams = processClass.InvokeMethod("Create",inParams, null); // Wait for 1 Second to start the Process System.Threading.Thread.Sleep(1000); // Get the Unique Process ID after Process Creation processID = (uint)outParams["processId"]; //Query based on the received processID and get the Process Name . ObjectQuery objObjectQuery = new ObjectQuery("Select name from Win32_Process Where ProcessID = '" + processID + "'"); ManagementObjectSearcher objMagObjSearcher = new ManagementObjectSearcher( objManagementScope, objObjectQuery ); ManagementObjectCollection objMagObjCollection = objMagObjSearcher.Get(); foreach( ManagementObject objManagementObject in objMagObjCollection ) { if(objManagementObject["name"] != null) processName = objManagementObject["name"].ToString(); } // foreach } }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups