0

I made a program that scans the subnet of my company and let me do lot of things on single client or on all clients together (like shutdown all). i leave a screenshot that show how my program works.

For some needs im trying to add a function with the name 'Process Kill' that shows me the list of the running Tasks (only 'Applications' Tab, not Background or System tasks) of the client selected and let me kill the one i choose.

The problem is that i found only functions that shows me all the process opened (that usually are not less than 100 considering system tasks) and i dont like it.

So im asking to you if someone knows how to get a list only of the Taksk opened in the 'Applications' tab.

Application Tab Screen

If u want add the code that let me kill it remotely too, will be useful.

Screenshot of the program

Thanks!

Updates:

This is what im actually using to get all the Processes in a MenuStrip Items

//IP Address of the remote machine
string ipAddress = row.Cells["IP"].Value.ToString();
ManagementScope scope = new ManagementScope(@"\\" + ipAddress + @"\root\cimv2");
scope.Options = connectoptions;

//Define the WMI query to be executed on the remote machine
SelectQuery query = new SelectQuery("select * from Win32_Process");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query)){
   ManagementObjectCollection collection = searcher.Get();
   foreach (ManagementObject process in collection){
      (conMenuStripIP.Items[5] as ToolStripMenuItem).DropDownItems.Add(process["Name"].ToString());
   }
}
Andreito
  • 1
  • 6
  • "*of the most important tasks*". and how do we know that that is? how do you define most important, personally my most important tasks might be different to yours, i like mine sweeper myself (a lot) – TheGeneral Nov 19 '19 at 08:34
  • Sorry, i mean only the application tab, going to edit the post – Andreito Nov 19 '19 at 09:18

1 Answers1

0

I think you can rely on the user initiated the process. Background processes should be initiated by special user accounts like (SYSTEM, LOCAL SERVICE, NETWORK SERVICE, etc.) If you exclude processes initiated by such users, you should have the list of applications

Also, you can handle it the other way around, if you have the list of user accounts accessing those client machines, you can kill processes initiated by them

To get User Name, you can use Process.StartInfo.UserName

Update based on the comments

To kill a remote process you can execute the below command through your code

taskkill.exe/S SYSTEM /U USERNAME /P PASSWORD /IM PROCESS  /F
Muhammad Gouda
  • 849
  • 8
  • 20
  • For each Machine i have IP, ComputerName and connected UserName (lot of more informations but i think this is the most important thing i need). How to get only processes ran by the User? – Andreito Nov 19 '19 at 10:07
  • Process.StartInfo.UserName didn't help? – Muhammad Gouda Nov 19 '19 at 10:54
  • the `Process.GetProcesses` funcion gets an exception 'Cannot connect to the remote Computer'. Thats why i wasnt using that type of funcion. I have like 60 Computers in my company, how to get access to Processes? I tried to use ManagementObjectSearcher with "select * from Win32_Processes, is there a way to get the StartInfo Username too? – Andreito Nov 19 '19 at 11:42
  • this is different form what you said in the question "i found only functions that shows me all the process opened". please edit your question to reflect your above comment as it is a different issue – Muhammad Gouda Nov 19 '19 at 12:28
  • Thanks for your help! I just added the portion of the code that im using to get the list of all processes opened, is there a way to get only processes opened from the user, like you explained before? – Andreito Nov 19 '19 at 12:37