<p>My code needs to determine how long a particular process has been running. But it continues to fail with an access denied error message on the <code>Process.StartTime</code> request. This is a process running with a User's credentials (ie, not a high-privilege process). There's clearly a security setting or a policy setting, or <em>something</em> that I need to twiddle with to fix this, as I can't believe the StartTime property is in the Framework just so that it can fail 100% of the time.</p>

<p>A Google search indicated that I could resolve this by adding the user whose credentials the querying code is running under to the "Performance Log Users" group. However, no such user group exists on this machine.</p>

[{'answer_id': 28727, 'author': 'Will Dean', 'author_id': 987, 'author_profile': 'https://Stackoverflow.com/users/987', 'pm_score': 1, 'selected': False, 'text': "<p>The underlying code needs to be able to call OpenProcess, for which you may require SeDebugPrivilege.</p>\n\n<p>Is the process you're doing the StartTime request on running as a different user to your own process?</p>\n"}, {'answer_id': 28874, 'author': 'Will Dean', 'author_id': 987, 'author_profile': 'https://Stackoverflow.com/users/987', 'pm_score': 0, 'selected': False, 'text': '<p>OK, sorry that didn\'t work...   I am no expert on ASP.NET impersonation, I tend to use app pools which I don\'t think you can do on W2K  Have you tried writing a tiny little test app which does the same query, and then running that as various users?   </p>\n\n<p>I am reluctant to post a chunk of MS framework code here, but you could use either Reflector or this: <a href="http://www.codeplex.com/NetMassDownloader" rel="nofollow noreferrer">http://www.codeplex.com/NetMassDownloader</a> to get the source code for the relevant bits of the framework so that you could try implementing various bits to see where it fails.  </p>\n\n<p>Can you get any other info about the process without getting Access Denied?</p>\n'}, {'answer_id': 28908, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 0, 'selected': False, 'text': "<p>I can enumerate the process (ie, the GetProcessById function works), and we have other code that gets the EXE name and other bits of information.</p>\n\n<p>I will give the test app a try. I'm also going to attempt to use WMI to get this information if I can't get the C# implementation working properly in short order (this is not critical functionality, so I can't spend days on it).</p>\n"}, {'answer_id': 28956, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 2, 'selected': False, 'text': '<p>Process of .Net 1.1 uses the Performance Counters to get the information. Either they are disabled or the user does not have administrative rights. Making sure the Performance Counters are enabled and the user is an administrator should make your code work.</p>\n\n<p>Actually the "Performance Counter Users Group" should enough. The group doesn\'t exist by default. So you should create it yourself. </p>\n\n<p>Process of .Net 2.0 is not depended on the Performance Counters.</p>\n\n<p>See <a href="http://weblogs.asp.net/nunitaddin/archive/2004/11/21/267559.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/nunitaddin/archive/2004/11/21/267559.aspx</a></p>\n'}, {'answer_id': 31792, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 3, 'selected': False, 'text': '<p>I\'ve read something similar to what you said in the past, Lars. Unfortunately, I\'m somewhat restricted with what I can do with the machine in question (in other words, I can\'t go creating user groups willy-nilly: it\'s a server, not just some random PC).</p>\n\n<p>Thanks for the answers, Will and Lars. Unfortunately, they didn\'t solve my problem.</p>\n\n<p>Ultimate solution to this is to use WMI:</p>\n\n<pre><code>using System.Management;\nString queryString = "select CreationDate from Win32_Process where ProcessId=\'" + ProcessId + "\'";\nSelectQuery query = new SelectQuery(queryString);\n\nManagementScope scope = new System.Management.ManagementScope(@"\\\\.\\root\\CIMV2");\nManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);\nManagementObjectCollection processes = searcher.Get();\n\n    //... snip ... logic to figure out which of the processes in the collection is the right one goes here\n\nDateTime startTime = ManagementDateTimeConverter.ToDateTime(processes[0]["CreationDate"].ToString());\nTimeSpan uptime = DateTime.Now.Subtract(startTime);\n</code></pre>\n\n<p>Parts of this were scraped from Code Project:</p>\n\n<p><a href="http://www.codeproject.com/KB/system/win32processusingwmi.aspx" rel="noreferrer">http://www.codeproject.com/KB/system/win32processusingwmi.aspx</a></p>\n\n<p>And "Hey, Scripting Guy!":</p>\n\n<p><a href="http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul05/hey0720.mspx" rel="noreferrer">http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul05/hey0720.mspx</a></p>\n'}]
['https://Stackoverflow.com/questions/28708', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1975282/']