Home All Groups Group Topic Archive Search About

System.Security.SecurityException, EnumWindows & Callback

Author
6 Apr 2007 8:47 PM
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

Author
8 Apr 2007 4:57 PM
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

Show quote
"Zamdrist" <zamdr***@gmail.com> wrote in message
news:1175892458.573435.304640@l77g2000hsb.googlegroups.com...
> 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
>
Author
9 Apr 2007 2:19 PM
Zamdrist
On Apr 8, 10:57 am, "Brian" <mccorb(remove_th***@cox.net> wrote:
>
> 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>

AddThis Social Bookmark Button