[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Access denied exception when calling  getprocesses

Posted on 2008-11-05
Medium Priority
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

Accepted Solution

ASliborsky earned 1500 total points
ID: 22884450
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 - http://msdn.microsoft.com/en-us/library/930b76w0(VS.71).aspx and http://msdn.microsoft.com/en-us/library/aa302424.aspx).

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

When ransomware hits your clients, what do you do?

MSPs: Endpoint security isn’t enough to prevent ransomware.
As the impact and severity of crypto ransomware attacks has grown, Webroot has fought back, not just by building a next-gen endpoint solution capable of preventing ransomware attacks but also by being a thought leader.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

872 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