CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2007
    Posts
    3

    Access is denied error when calling destroywindow

    I am getting an access is denied error message when calling the DestroyWindow() function in a .net windows application, here is the code:


    ArrayList RunningP;
    Process IEProc;
    Int32 temp;
    Int32 i = 0;
    Boolean b;

    RunningP = new ArrayList(Process.GetProcessesByName("iexplore"));
    if (RunningP.Count > 0)
    {
    IEProc = (Process)RunningP[i];
    b = DestroyWindow(IEProc.Handle);
    i = i + 1;
    temp = GetLastError();
    }

    the variable temp is where i find error code 5 which is access is denied. I also have these delegate methods defined on this page:

    [DllImport("User32.dll")]
    public static extern System.Boolean DestroyWindow(IntPtr hWnd);
    [DllImport("kernel32.dll")]
    public static extern System.Int32 GetLastError();

    I am logged on as local administrator, so not sure what is causing this error message I have search on this site and others and cant seem to find a fix for this, can anyone help?

    Regards

    Joe

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Access is denied error when calling destroywindow

    DestroyWindow can happen only through the thread that created the window. Perhaps that is the reason. Why are you trying to destroy the window in such a way though ?

  3. #3
    Join Date
    Jul 2007
    Posts
    3

    Re: Access is denied error when calling destroywindow

    Oh i see, thanks for that info, reason i wanted to close window was that the user will be in an application requiring authentication, closing the window and opening a new one dedirecting them to a specific page in the app was the easiest way i could see to do it, this obvioulsy is not an option. I am now having another problem though, i am using SetForegroundWindow code as follows:

    ArrayList RunningP;
    Process IEProc;
    Int32 temp;
    Int32 i = 0;
    Boolean b = false;
    System.IntPtr o;

    RunningP = new ArrayList(Process.GetProcessesByName("iexplore"));
    if (RunningP.Count > 0)
    {
    temp = GetLastError();
    IEProc = (Process)RunningP[i];
    b = SetForegroundWindow(IEProc.Handle);
    i = i + 1;
    temp = GetLastError();
    }
    }

    this returns true when function is run no error code is produced but its not setting the window to the foreground that I have requested, any ideads what might cause this?

    Regards

    Joe

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Access is denied error when calling destroywindow

    .NET Framework Class Library
    Process Members
    Handle Gets the associated process's native handle.
    Afraid, Process.GetProcessesByName("iexplore") eventually gives you a process handle. You cannot use process and window handles interchangeably - because of their totally different nature.
    Last edited by Igor Vartanov; April 16th, 2008 at 04:52 AM.
    Best regards,
    Igor

  5. #5
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Access is denied error when calling destroywindow

    Quote Originally Posted by Joepinder
    Oh i see, thanks for that info, reason i wanted to close window was that the user will be in an application requiring authentication, closing the window and opening a new one dedirecting them to a specific page in the app was the easiest way i could see to do it, this obvioulsy is not an option.
    You could do that by implementing some kind of messaging between your applicaton and target application. For that, you would need to first get the window handle. APIs like FindWindow might help in reaching a specific window.

  6. #6
    Join Date
    Jul 2007
    Posts
    3

    Re: Access is denied error when calling destroywindow

    thanks for you help on this, ive gone for the simple approach of just using the existing window and redirecting from where ever it is.

    Regards

    Joe

  7. #7
    Join Date
    Dec 2007
    Posts
    17

    Re: Access is denied error when calling destroywindow

    It's needless to destroy, C# already gives you a smart close to move on,
    loading dll to use api is not neccessary either

  8. #8
    Join Date
    Dec 2007
    Posts
    50

    Re: Access is denied error when calling destroywindow

    Sorry every1 for hijacking the thread
    but could you tell me how to close an application remotely: client-client, client-server and server-client ? does the IPaddress alone have no meaning at to help me accomplish this ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured