1

I'm currently doing, in one of my project, a Homemade Task Manager. Everything was working fine until I implemented other functionality in my program. Exceptions are thrown as soon as I add the following lines in comments

Exception thrown: 'System.UriFormatException' in System.dll

Exception thrown: 'System.ComponentModel.Win32Exception' in System.dll

And Whenever I Start the program .exe made with the release build I got this:

System.ComponentModel.Win32Exception (0x80004005): Access is denied

Thanks

foreach (Process p in active_process)
{
    
    ListViewItem process_list = new ListViewItem(p.ProcessName);
    p.Refresh();
    listView1.Items.Add(process_list); //Add Processes Name in Column 1
    process_list.SubItems.Add(p.Id.ToString()); //Add Processes ID in Column 2
    process_list.SubItems.Add(p.WorkingSet64.ToString()); //Add The physical memory used by processes in Column 3
   //process_list.SubItems.Add(p.PriorityClass.ToString());//Add The priority degree of each processes in Column 4
   //process_list.SubItems.Add(p.StartTime.ToString());  //Add The time at which each processes started in Column 5              
    process_list.Tag = p;
                 
}
Community
  • 1
  • 1
jj0978
  • 11
  • 2

2 Answers2

1

You cannot access process list without administrative privileges, so you should request them.

See How to request administrator permissions when the program starts?

Szörényi Ádám
  • 1,223
  • 13
  • 17
  • I Did that, but It keeps doing the same thing and I saw that the manifest is as well linked in the Project/Properties/Application window – jj0978 Jun 20 '17 at 00:31
1

Make your program run as admin by right clicking on project then Add then application manifest file and change the requestedExecutionLevel to this

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

This way your program will ask for admin rights at the beginning

Amine Messaoudi
  • 2,141
  • 2
  • 20
  • 37