NetXMS Support Forum

English Support => General Support => Topic started by: stoffmann on June 18, 2025, 09:26:34 AM

Title: Monitor a process from specific user with Process.CountEx fails
Post by: stoffmann on June 18, 2025, 09:26:34 AM
Hi,
I have to monitor if a process is running under a specific user in Windows.

I use Process.CountEx for doing that.

In Taskmanager the username is shown like AD001\z004abcd
Processname is EB_BPM.exe

I tried: Process.CountEx("EB_BPM.exe",,"AD001\z004abcd")
and ( in case the Backslash is the problem):  Process.CountEx("EB_BPM.exe",,"(?i)z004abcd")

Both fail.
Using just  Process.CountEx("EB_BPM.exe") works, but I need to have the username.


Using  NetXMS 5.2.1
Any idea?

Stefan
Title: Re: Monitor a process from specific user with Process.CountEx fails
Post by: Filipp Sudanov on June 20, 2025, 03:16:46 PM
Did you try
Process.CountEx("EB_BPM.exe",,"z004abcd")
?
Title: Re: Monitor a process from specific user with Process.CountEx fails
Post by: stoffmann on June 23, 2025, 11:24:42 AM
I tried. It's also not working. Always returning 0.

In logfile with Loglevel 7 I find:

2025.06.23 09:08:32.521 *D* [comm.cs.1          ] Requesting metric "Process.CountEx("EB_BPM.exe",,"z004abcd")"
2025.06.23 09:08:32.555 *D* [comm.cs.1          ] GetMetricValue("Process.CountEx("EB_BPM.exe",,"z004abcd")"): 0 (SUCCESS) value = "0"

But the process is running.
Title: Re: Monitor a process from specific user with Process.CountEx fails
Post by: stoffmann on June 26, 2025, 03:30:37 PM
Do You need more information to solve this? Please let me know.

Regards

Stefan
Title: Re: Monitor a process from specific user with Process.CountEx fails
Post by: Victor Kirhenshtein on July 01, 2025, 01:04:39 PM
how do you see this process in "Processes" view for that node?
Title: Re: Monitor a process from specific user with Process.CountEx fails
Post by: stoffmann on July 01, 2025, 01:12:26 PM
In process view the column user is almost empty.


Only BUILTIN\Administrators shows up for some processes.
Title: Re: Monitor a process from specific user with Process.CountEx fails
Post by: Filipp Sudanov on July 01, 2025, 03:15:45 PM
Well, that explains why the metric does not return what you expect. 

How do you run the agent - under SYSTEM user or in some other way?
Title: Re: Monitor a process from specific user with Process.CountEx fails
Post by: stoffmann on July 02, 2025, 08:20:05 AM
We have the agent running with a domain account, that is member of the Administrators group.
Title: Re: Monitor a process from specific user with Process.CountEx fails
Post by: Filipp Sudanov on July 02, 2025, 09:22:41 AM
Please try to run the agent under system user to see if that makes any difference
Title: Re: Monitor a process from specific user with Process.CountEx fails
Post by: stoffmann on July 02, 2025, 11:26:53 AM
Running it as system now shows the usernames in the Process View. But why doesn't it work with an administrative account?
Title: Re: Monitor a process from specific user with Process.CountEx fails
Post by: Filipp Sudanov on July 08, 2025, 01:25:51 PM
Agent uses GetSecurityInfo win api function, please check information about needed access rights here:
https://learn.microsoft.com/en-us/windows/win32/api/aclapi/nf-aclapi-getsecurityinfo#remarks