Failure of the .StartTime process

My code should determine how long a particular process runs. But it continues to fail with an access denied error message in the request Process.StartTime. This is a process that runs with user credentials (i.e. Not with a high privilege level). Obviously, a security setting or a policy setting or something I need to fix to fix it, because I can’t believe that the StartTime property is in the Framework so that it can’t work for 100% of the time.

A Google search showed that I can solve this problem by adding a user whose credentials run the request code to the Performance Log Users group. However, there is no such user group on this machine.

+3
source share
5 answers

I read something similar to what you said in the past, Lars. Unfortunately, I am somewhat limited by what I can do with the machine in question (in other words, I cannot create user groups perforce: this is a server, and not just some random PC).

Thanks for the answers, Will and Lars. Unfortunately, they did not solve my problem.

The ultimate solution for this is to use WMI:

using System.Management;
String queryString = "select CreationDate from Win32_Process where ProcessId='" + ProcessId + "'";
SelectQuery query = new SelectQuery(queryString);

ManagementScope scope = new System.Management.ManagementScope(@"\\.\root\CIMV2");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection processes = searcher.Get();

    //... snip ... logic to figure out which of the processes in the collection is the right one goes here

DateTime startTime = ManagementDateTimeConverter.ToDateTime(processes[0]["CreationDate"].ToString());
TimeSpan uptime = DateTime.Now.Subtract(startTime);

Parts of this have been cleared from the code project:

http://www.codeproject.com/KB/system/win32processusingwmi.aspx

", !":

http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul05/hey0720.mspx

+3

.Net 1.1 . , . , , - , .

, . . .

.Net 2.0 .

. http://weblogs.asp.net/nunitaddin/archive/2004/11/21/267559.aspx

+2

OpenProcess, SeDebugPrivilege.

, StartTime, ?

+1

, , ... ASP.NET, , , W2K. , ?

MS framework , Reflector : http://www.codeplex.com/NetMassDownloader, , , , .

, ?

0

(.. GetProcessById), , EXE .

I will try a test application. I will also try to use WMI to get this information if I can not correctly implement the C # implementation in a short time (this is not critical functionality, so I can not spend days on it).

0
source

Source: https://habr.com/ru/post/1696545/


All Articles