7

Good afternoon guys. Long time no hear from me and I'm sorry about that. Had a lot health problems to fight.

I'm currently trying to list all processes that are running on my pc with a C# program. VS is running with admin rights but I'm still getting an error: "System.ComponentModel.Win32Exception: Access denied Error"
I tried googling it but if found the answer I didn't understand it.
Please help me.

Comments
  • 2
    Gotta run it as admin.

    You can also request elevated privileges for you program in one of the config files I forget how, but Google it.
  • 2
    https://stackoverflow.com/questions
    /15393288/how-do-i-make-a-console-app-always-run-as-an-administrator
  • 1
    Run Visual Studio as Admin too (Right click -> Run As Administrator)
  • 1
    @delegate212

    VS runs as admin,

    app.manifest is modified

    Error still occurs. Thanks for your input though.
  • 2
    Works on my machine. You must be the worst developer in the world. THE WORLD!!

    - signed: the first few responses on StackOverflow

    Seriously, that's weird. Your networking/devops department push an unnecessary security update?

    Dealing with that right now. VS isn't playing well with others (and it is running as admin).

    I'm trusted with accessing million $$ systems, access to credit card tokens, customer data, etc, but try to debug a WebAPI project? Oh no, can't allow VS to run IIS Express, that's a security risk.
  • 0
    @PaperTrail i'm working on my own computer at home so IT department setting up something weird isnt a problem.

    It's a 64bit Win10 if that helps.
  • 1
    Does it break on any specific process?
  • 0
    @delegate212 jup. WUDFHost. Dont know what that is. (Seems to be something driver related from Windows)
  • 0
    @KittyMeowstika

    Just handle the exception. In reality you cannot expect all users to have total permission over all processes anyway. I'd also exclude system processes too.

    System.Diagnostics.Process.GetProcesses()
    .Where(e => e.ProcessName != "Idle" && e.ProcessName != "System");

    foreach (System.Diagnostics.Process proc in processes)
    {

    try
    {
    Console.WriteLine($"Process: {proc.ProcessName} ID: {proc.Id} CPU Time: {proc.TotalProcessorTime}");
    }
    catch (System.ComponentModel.Win32Exception ex)
    {
    //log exception
    }

    }
  • 2
    @delegate212 thank you! I'm gonna try that.
    The only user that's going to use that is my husband. He gave me this neat little programming task to keep me busy while I'm recovering from cancer/ chemotherapy.
  • 0
    @delegate212 doesn't quite work. there seems to be a cast missing. what do i need to change?
  • 1
    @KittyMeowstika

    Assuming its
    System.Diagnostics.Process.GetProcesses()
    .Where(e => e.ProcessName != "Idle" && e.ProcessName != "System");

    Then store it as ienumerable<Process>
  • 0
    What if you go to the executable file and run it directly as administrator?
  • 0
    @AlgoRythm still happening sadly
  • 0
    @delegate212 But Process.GetProcesses() returnes an array afaik?
  • 0
    Found the reason guys. It's the fucking Idle process. God knows why but apparently admin privileges aren't sufficient enough to get certain information from that process (other than id which is 0). God i hate microsoft.
  • 1
    @delegate212 just as a sidenote, checking the process name like that could open you up to confusing bugs or security holes. Admittedly probably not in your case though.
  • 1
    @KittyMeowstika

    > keep me busy while I'm recovering from cancer/ chemotherapy.

    I'm happy you're busy and keeping focused on life outside of cancer.

    I'm also very sorry you are having to go thru that battle. Cancer sucks.
  • 0
    @PaperTrail thank you. It has been/ still is a hard time. But I'm on the best way to a full recovery. Hopefully I'm able to work again (at least a bit) by January.
Add Comment