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

Win32_Process

Scheduled Pinned Locked Moved C#
questiondatabasehelptutorial
7 Posts 2 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 } }

    D 1 Reply Last reply
    0
    • S skrishnasarma

      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 } }

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      IIRC, the WMI Win32_Process class doesn't support RunAs. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        IIRC, the WMI Win32_Process class doesn't support RunAs. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        S Offline
        S Offline
        skrishnasarma
        wrote on last edited by
        #3

        Thanks Then Can you tell me how to achive to launch a process with different username /password. Regards

        D 1 Reply Last reply
        0
        • S skrishnasarma

          Thanks Then Can you tell me how to achive to launch a process with different username /password. Regards

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          On a remote machine? You can't. It's a HUGE security violation. You can, however, have a process on that machine launch the application for you under a different account. You might want to check into PSTools[^] from SysInternals. Be warned though... Virus scanners are tagging PSEXEC as a suspect program and throwing up virus warnings about it. This goes for any other known application that allows a remote machine to launch a program locally. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          S 1 Reply Last reply
          0
          • D Dave Kreskowiak

            On a remote machine? You can't. It's a HUGE security violation. You can, however, have a process on that machine launch the application for you under a different account. You might want to check into PSTools[^] from SysInternals. Be warned though... Virus scanners are tagging PSEXEC as a suspect program and throwing up virus warnings about it. This goes for any other known application that allows a remote machine to launch a program locally. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            S Offline
            S Offline
            skrishnasarma
            wrote on last edited by
            #5

            Hi Dave Kreskowiak This process launch is not in remote machine,for local machine only. My requirement is I wand to launch a new process in the local machine with different username/ password (Not the one user currently logged in) Regards

            D 1 Reply Last reply
            0
            • S skrishnasarma

              Hi Dave Kreskowiak This process launch is not in remote machine,for local machine only. My requirement is I wand to launch a new process in the local machine with different username/ password (Not the one user currently logged in) Regards

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              If you want to launch a process as a different user, then you have several options, all of which involve P/Invoking various Win32 API functions. I would suggest you start by reading CreateProcessAsUser[^] on MSDN and compar your requirements with the options listed. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              S 1 Reply Last reply
              0
              • D Dave Kreskowiak

                If you want to launch a process as a different user, then you have several options, all of which involve P/Invoking various Win32 API functions. I would suggest you start by reading CreateProcessAsUser[^] on MSDN and compar your requirements with the options listed. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                S Offline
                S Offline
                skrishnasarma
                wrote on last edited by
                #7

                Thanks a Lot for your information.

                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