Print all processes

studio
process

#1

hi, how to print all the running processes?
i know we can get all list from Get Processes activity and to loop through to print.
how to print all the process names?


Start process creating multiple instances of conhost.exe
#2

Hey @nagakula

You can use .ProcessName. It will Give you a Process Name.

Reference Sample - Getallprocess_name.xaml (5.7 KB)

Regards…!!
Aksh


#3

Thanks for quick response. I didn’t selected the object type as Process in for each activity.


#4

I was interested in retrieving (or ending) all the processes for only the currently logged in user. For example, on a server there could be multiple users signed on or active and I wouldn’t want to end an Excel process if it’s being used under a different user account. Or maybe the Get Processes already does that? Let me know if you know a way to do what I’m asking.

Thanks. :slight_smile:


#5

Hey @ClaytonM

Mate ii have the same thinking like u :wink:

I though the same thing at my earliest days :slight_smile:(Approx 4 months back)

Fortunately i have that thing for you. Although have created for INternal use :wink: but Sharing is caring :slight_smile:

processkillforusersample.xaml (10.4 KB)

Let me know it fullfilled the thing or not :slight_smile: and any advice open for to make it more better :slight_smile:

Regards…!!
Aksh


#6

Perfect!


#7

@aksh1yadav
I finally went and looked at getting a kill process per user script, since my RPA team here were pushing for one. :roll_eyes: :laughing:

Your sample I don’t believe was working because it was looping through each item regardless of userid. However, it did strike some ideas and ultimately gave me the needed results!

So what I ended up doing is storing the CurrentSession ID and using that in the condition. I also added additional logic to kill explorer and reopen. And, I put all the process names in an array.

Works pretty good in my limited testing.
KillProcessesPerUser.xaml (13.8 KB)

Thanks.

ClaytonM


How to kill the excel process which is running by current user
#8

Hey @ClaytonM

It is working and it will work mate.

There are some points i will tell you about the working…

i have used Looping because it was not for excel only. if i want to kill some other process as well so i have used running process list.

Didn’t check the session id approach but regarding my sample Every process running on a system either local system or remote system one unique identifier has associated with them So even if you will call them by Process.GetProcessById(Process.Id) it will return a new Process component, given the identifier of a process on the local computer.

and if you will look into my sample i have taken the current user name as well but why i have not put it in if condition because this is for user running into his account not for server system to kill for a specific user account.if you want to get only for particular user account excel process then you can use Process.GetProcessesByName Method (String) or GetProcessById(Int32,String) by passing second argument as a name of the computer on the network.

Process.GetProcessById

  • GetProcessById(Int32) - Returns a new Process component, given the identifier of a process on the local computer.

  • GetProcessById(Int32,String) - Returns a new Process component, given a process identifier and the name of a computer on the network.

GetProcessById(Int32)-

GetProcessById(int processId)
Parameters

processId-

Type: System.Int32
The system-unique identifier of a process resource.

Return Value
Type: System.Diagnostics.Process
A Process component that is associated with the local process resource identified by the processId parameter.

  • Use this method to create a new Process component and associate it with a process resource on the local computer.
  • A process Id can be retrieved only for a process that is currently running on the computer.
  • The process resource must already exist on the computer, because GetProcessById(Int32) does not create a system resource, but rather associates a resource with an application-generated Process component.
  • After the process terminates, GetProcessById(Int32) throws an exception if you pass it an expired identifier.
  • On any particular computer, the identifier of a process is unique. GetProcessById(Int32) returns one process at most. If you want to get all the processes running a particular application, use GetProcessesByName(String).

*If multiple processes exist on the computer running the specified application, GetProcessesByName(String) returns an array containing all the associated processes. You can query each of these processes in turn for its identifier. The process identifier can be viewed in the Processes panel of the Windows Task Manager. The PID column displays the process identifier that is assigned to a process.

Note- and regarding your session approach to get current session details you have to relay on explorer :slight_smile: that is why you are opening and closing it to get session id :wink:

Regards…!!
Aksh


#9

Thank you for the info.
The reason I say your sample wasn’t working was because in your Kill Process, you only kill the item with no If condition at all. Therefore, you kill each item you loop through, which is every process on the machine that equals the ProcessName in your If condition. I also verified this with WriteLine.

So, I needed to filter the items by some “Id” that notates the current user or session and only kill the processes within that “Id”. I guess I’m not understanding how your sample works, because from my perspective it kills every process in the process_list.

GetProcessById(item.Id) was returning the same process as the item within the loop, so I also don’t see the benefit of this unless there’s some relation to the current_user or sessionId. Also, you were not using this variable anywhere in your script.

In the end, using your sample I could not find the relation to the current logged in user to the process that was going to be killed. This is why I made an adjustment and stored the CurrentSessionId, which then I could use in the If condition next to if it equals “EXCEL”. It was a pretty simple adjustment, but I still don’t understand how your initial sample was working (maybe I missed something?)

The “explorer” parts were not related to the sessionId or anything; it was only intended if you want to kill the explorer.exe you need to start it again since it is required for the Windows taskbar to show.

Sorry if we are just confusing each other :rofl:
Thanks.

Clayton.


#10

I updated some things in my version to use a filtered list instead of an If condition so it only loops through the items that are of the correct session id and equals a process name in the list. Also, migrated the Array of process names to a text file, as well as made some improvements to the logic that re-starts the explorer process if it is killed.
KillProcessesPerUser.zip (4.7 KB)
I’m happy to share and always looking to improve. :nerd_face:


#11

Well check out new things :slight_smile: and let me know

shortest way -

Windows has a built-in command “TASKKILL” to kill a process.

if you want to kill the excel process for user corp\aksh then

TASKKILL /F /FI "USERNAME eq corp\aksh" /IM EXCEL.EXE

String Current_user = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Replace(“Servername”,"")

"TASKKILL /F /FI 'USERNAME eq "+Current_user+"' /IM EXCEL.EXE

Excel_kill_for_user_cmd.xaml (5.2 KB)

second way is the same but with now user sid way :slight_smile:
processkillforusersample.xaml (10.4 KB)

There is still more way like WMI and so and so.

Regards…!!
Aksh


How to kill the excel process which is running by current user
#12

Good info.
Yeah the version of your sample I downloaded yesterday was old. I’ll store your good one for future reference.

Thanks!


#13

you can append the filter one and re upload for others. @ClaytonM. Thanks for notify things and got things from such conversation :slight_smile:

Thanks a Ton mate


#14

processkillforusersample.xaml (8.9 KB)
Sure I can share this too: Here is your sample with alternate method of filtering the processes down before the loop.

It doesn’t have the additional logic for killing explorer.exe though, but I have that in my version I posted above as well.

Thanks.


How to close the existing chrome session?. i mean what activities i can use