Access denied exception when calling getprocesses

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            
Next

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.



ZAKHurstAsked:
Who is Participating?
 
ASliborskyConnect With a Mentor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.