System.Security.SecurityException, EnumWindows & Callback

Z

Zamdrist

Running an application executable (release) runs find on my computer:

"The application attempted to perform an operation not allowed by the
security policy."...
System.Security.SecurityException:
System.Security.Permissions.SecurityPermission...

Thoughts?

I was able to narrow the problem down the EnumWindows API call and
AddressOf Callback routine here:

Public Sub InitList()
Dim cb As CallBack
cb = New CallBack(AddressOf MyCallBack)
EnumWindows(cb, 0)
End Sub

Public Function MyCallBack(ByVal hwnd As IntPtr, ByVal lParam As
IntPtr) As Boolean

Dim intLen As Integer = GetWindowTextLength(hwnd) + 1

If intLen > 1 Then
Dim strText As New StringBuilder(intLen)

Try
GetWindowText(hwnd, strText, intLen)

If IsWindowEnabled(hwnd) And IsWindowVisible(hwnd) Then
lvWindows.Items.Add(strText.ToString).SubItems.Add(hwnd.ToString)
End If

Catch ex As Exception
Trace.WriteLine(ex.ToString)
End Try

End If
Return True
End Function

Public Delegate Function CallBack(ByVal hwnd As IntPtr, ByVal lParam
As IntPtr) As Boolean
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As
CallBack, ByVal lParam As Integer) As Integer
 
B

Brian

If you tried to execute it from a nework share/drive and that is what did
not work, try going to control panel->admin tools->.net framework config
1.1/2.0 etc.
Then adjust zone security. Adjust all the zones to allow everything and then
start backing them off again. This has worked for most everything I have
deployed although I was looking for answers myself because it doesn't work
on everything.

brian
 
Z

Zamdrist

If you tried to execute it from a nework share/drive and that is what did
not work, try going to control panel->admin tools->.net framework config
1.1/2.0 etc.
Then adjust zone security. Adjust all the zones to allow everything and then
start backing them off again. This has worked for most everything I have
deployed although I was looking for answers myself because it doesn't work
on everything.

brian

Thanks Brian.

What an absolute pain in the ass programming has become. <sigh>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top