Access denied exception when calling  getprocesses

Posted on 2008-11-05
Last Modified: 2013-12-04
We have an application that works fine 95% of the time for all our customers, however 2 cusotmers are reporting a fatal error "Access Denied"

This following is a sample of the code , the applciation performs this operation for a number of reasons the following is the simplest case, just checking if the current problem is already running on the machine.

      Loop through processes on current  machine to check that application is only being run by a single user, important if being run on  Windows Server

For Each proc As Process In System.Diagnostics.Process.GetProcesses
          Check each process name with process name against current process name
    If proc.ProcessName = System.Diagnostics.Process.GetCurrentProcess.ProcessName Then
              If Process names match and the Process IDs are different then another instance of the application is running
        If proc.Id <> System.Diagnostics.Process.GetCurrentProcess.Id Then
                      MessageBox.Show(System.Diagnostics.Process.GetCurrentProcess.ProcessName + " already Running ")
                      Exit Sub
        End If            
    End If            

This is failing on Window 2003 service pack 2  at one of our customers, but the code works fine for us and other customers in the same envirnoment. This is a .NET framework 1.1 solution .

We have checked and double checked that the user  has administrator priveleges , still we get the error though, when we comment out the above code and the application continues to the next occurrence of getprocesses.

Question by:ZAKHurst
    1 Comment
    LVL 3

    Accepted Solution

    Check, may be it's just Code Access Security (CAS) exception  - user may have rights, but .NET CLR prevents some code from running if code has no appropriate permissions (Read corresponding section in MSDN - and

    You can check whether code has necessary permnissions by calling Demand, or bypass such checks by calling Assert on permission sobjects.

    Also, you can set Full Trust permissions to your application to avoid these checks.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Article by: btan
    The intent is not to repeat what many has know about Ransomware but more to join its dots of what is it, who are the victims, why it exists, when and how we respond on infection. Lastly, sum up in a glance to share such information with more to help…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now