Link to home
Start Free TrialLog in
Avatar of Steven-Devry
Steven-Devry

asked on

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
Avatar of UncleMidriff
UncleMidriff

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?
Avatar of Steven-Devry

ASKER

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
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?"
ASKER CERTIFIED SOLUTION
Avatar of UncleMidriff
UncleMidriff

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial