System.ComponentModel.Win32Exception: Access is denied

this is the error i get when i run the piece of code below on some machines:

System.ComponentModel.Win32Exception: Access is denied
   at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId,
Int32 access, Boolean throwIfExited)
   at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32
processId)
   at System.Diagnostics.Process.get_Modules()
   at System.Diagnostics.Process.get_MainModule()
   at System.Diagnostics.Process.get_ProcessName()
   at ExcelDemo.clsExcelHost..ctor() in D:\Bert Opdracht\Excel Demo for
Windows XP version\ExcelDemo\Classes\clsExcelHost.vb:line 13
   at ExcelDemo.DataBaseSelectForm.MAcroRefresh(String inputworkbook) in

the code that causes this is the following code
 Dim process1() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses()
        xlApp = CreateObject("Excel.Application")
        Dim process2() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses()
        Dim ct1 As Integer
        Dim ct2 As Integer
        Dim blnUnique As Boolean

this is the line where the error is called on        For ct1 = 0 To process1.GetUpperBound(0)
            If process2(ct1).ProcessName = "EXCEL" Then
                blnUnique = True
                For ct2 = 0 To process1.GetUpperBound(0)
                    If process1(ct2).ProcessName = "EXCEL" Then
                        If process2(ct1).Id = process1(ct2).Id Then
                            blnUnique = False
                            Exit For
                        End If
                    End If
                Next
                If blnUnique = True Then
                    procId = process2(ct1).Id
                    Exit For
                End If
            End If
If somebody can give me a clue why this is happening i would be
very thankfull

Steven Devry
Steven-DevryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

UncleMidriffCommented:
I don't know if this helps, but I copied the code you posted into a sub procedure and it worked fine for me.

Could you tell us some more about the computers this is working on vs. the computers it isn't working on?
0
Steven-DevryAuthor Commented:
The difference between the machines in one case is the oparating system.
For the Pc having Windows XP , the code is running fine.
Fot the PC where the operating system is Windows 2000, thr code is failing.
The only difference for the rest is, that the one Pc is a laptop and the other
PC is a desktop.
But that doesn't seem relevant to me.
For the rest the user rights are both identical
0
UncleMidriffCommented:
Well the system that it ran fine on for me is using Windows 2000.

I'm wondering if this is related to the other access denied problem you posted about.

What is line 13 of  "D:\Bert Opdracht\Excel Demo for Windows XP version\ExcelDemo\Classes\clsExcelHost.vb?"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

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.