Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried using DestroyWindow to remotely destroy a password prompt dialog box that keeps popping-up every time I remotely open a particular PDF document. (It doesn't work!)

Before this I was also trying SendMessage with the WM_CLOSE value as shown below:


Public Const WM_CLOSE = &H10

Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, _
         ByVal wParam As IntPtr, ByRef lParam As IntPtr) As IntPtr

    Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, _
        ByVal wParam As Integer, ByRef lParam As IntPtr) As Integer

    Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, _
        ByVal wParam As Integer, ByRef lParam As Integer) As Integer

    Declare Auto Function SendMessage Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, _
        ByVal wparam As Integer, ByVal lparam As System.Text.StringBuilder) As IntPtr

Dim dialog_title As String = "Password"
Dim hwnd As IntPtr = FindWindow(vbNullString, dialog_title)
SendMessage(hwnd, WM_CLOSE, 0, 0)



When I do this virtually nothing happens (nothing ever happens).
Upon keen observation I did notice that the cursor blinking in the password input field went off for about half-a-second then started blinking again; that's all.

Maybe I'm not using the SendMessage function right; I dunno. I've tried so many ways.

Can anyone see whats wrong with my code or suggest a "sure-fire" way that might work to get rid of the modal dialog.

Thanks.
Posted

I looked at your solution and that's exactly what I would have tried. Two questions for you:

1. Have you used the debugger to look at the value of hwnd? You should make sure it's the right window.

2. If on Vista or later, have you tried running this program as an admin?
 
Share this answer
 
Question - is the parent app recreating the dialog right away because no password was entered ?
 
Share this answer
 
Christian Graus says:

Question - is the parent app recreating the dialog right away because no password was entered ?



No. When I manually click any button on the password dialog, apart from the OK button, it closes and never re-appears unless the document is re-opened.
 
Share this answer
 
Hans Dietrich says:

I looked at your solution and that's exactly what I would have tried. Two questions for you: 1. Have you used the debugger to look at the value of hwnd? You should make sure it's the right window. 2. If on Vista or later, have you tried running this program as an admin?



Yeah, the hwnd is a large +ve integer. And i don't have any other windows open or visible with the "Password" title.

Also, I am using Windows XP.
 
Share this answer
 
v2
You need to verify that you have the correct window handle. Use Spy++ to confirm.
 
Share this answer
 
Hans Dietrich says:

You need to verify that you have the correct window handle. Use Spy++ to confirm.


There seems to be two (2) window handles associated with the "Password" dialog box. One is static and is always 32770, while the other changes with each new instance of the dialog window. Invoking SendMessage on both handles yields the same result- nothing!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900