System.ComponentModel.Win32Exception: Access is denied

Posted on 2004-11-26
Last Modified: 2008-01-09
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
   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
                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
Question by:Steven-Devry
    LVL 2

    Expert Comment

    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?

    Author Comment

    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
    LVL 2

    Expert Comment

    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?"
    LVL 2

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    794 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