Win32_Process
-
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 } }
-
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 } }
IIRC, the WMI Win32_Process class doesn't support RunAs. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
IIRC, the WMI Win32_Process class doesn't support RunAs. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Thanks Then Can you tell me how to achive to launch a process with different username /password. Regards
-
Thanks Then Can you tell me how to achive to launch a process with different username /password. Regards
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
-
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
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
-
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
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
-
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
Thanks a Lot for your information.