|
-
April 15th, 2008, 09:56 AM
#1
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
-
April 15th, 2008, 04:51 PM
#2
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 ?
-
April 16th, 2008, 04:28 AM
#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
-
April 16th, 2008, 04:39 AM
#4
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
-
April 16th, 2008, 01:42 PM
#5
Re: Access is denied error when calling destroywindow
 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.
-
April 23rd, 2008, 04:45 AM
#6
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
-
April 25th, 2008, 09:02 PM
#7
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
-
April 25th, 2008, 09:23 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|