|
-
Aug 12th, 2006, 09:31 AM
#1
Thread Starter
Hyperactive Member
[2.0] Process owner
I've been using the Process class to get information about different processes, but I can't get the process owner. I've looked on MSDN about processes but i couldn't find anything. Is there a way to do this through API?
Sorry if this question has been asked before.
-
Aug 12th, 2006, 03:51 PM
#2
Re: [2.0] Process owner
I think it's
Code:
Process1.StartInfo.UserName;
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Aug 13th, 2006, 12:59 PM
#3
Thread Starter
Hyperactive Member
Re: [2.0] Process owner
Thanks for reply, but i had no luck with that. Anyone else?
-
Aug 14th, 2006, 03:39 PM
#4
Re: [2.0] Process owner
I don't have .Net 2.0 on this machine, but my method should still work. You will need to add a reference to System.Management to your project:
Code:
StringBuilder objSB = new StringBuilder();
string[] s= new string[2];
//Use WMI to get the process info
ManagementClass objMan = new ManagementClass ( @"root\cimv2:Win32_Process") ;
//Loop through each process
foreach ( ManagementObject objManOb in objMan.GetInstances() )
{
//Call the get owner method, which gets us the username and domain of the user that started the process
objManOb.InvokeMethod("GetOwner",(object[])s);
objSB.Append (objManOb["Name"] + " - " + s[1] + "\\" + s[0] + Environment.NewLine );
}
MessageBox.Show(objSB.ToString());
-
Aug 18th, 2006, 01:47 PM
#5
Thread Starter
Hyperactive Member
Re: [2.0] Process owner
Im looking at that and thinking it should work, and when i tested that code, it did. But i need to get the owner of individual processes. So i tried to modify it a little, but no luck. Heres the code ive used:
Code:
private void button1_Click(object sender, EventArgs e)
{
try
{
textbox1.Text = GetOwner(listBox1.SelectedItem);
}
catch { MessageBox.Show("Error. No Process Selected?"); }
}
string GetOwner(string ProcessName)
{
StringBuilder objSB = new StringBuilder();
string[] s = new string[2];
//Use WMI to get the process info
ManagementClass objMan = new ManagementClass(@"root\cimv2:Win32_Process");
//Loop through each process and check name against WMI name
foreach (ManagementObject objManOb in objMan.GetInstances())
{
objManOb.InvokeMethod("GetOwner", (object[])s);
if (objManOb["Name"].ToString() == ProcessName)
{
objSB.Append(s[0]);
}
}
return objSB.ToString();
}
Its not returning errors, just nothing is showing up in the textbox. help?
-
Aug 20th, 2006, 07:36 PM
#6
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|