Re: Check for permission does not work

From: Scott Swigart (scott_at_3leaf.com)
Date: 10/29/04

  • Next message: Novice: "Looking at specifics of bit encryption negotiated during SSL hands"
    Date: Fri, 29 Oct 2004 09:28:03 -0700
    
    

    You shouldn't need the x.Flags line. The following sample throws a security
    exception when it demands the UnmanagedCode permission. If you comment out
    the attribute, then the demand works. Hope this helps.

    Imports System.Security.Permissions

    Module Module1

        <SecurityPermissionAttribute(SecurityAction.Deny, UnmanagedCode:=True)>
    _
        Sub Main()
            Dim s As New
    SecurityPermission(SecurityPermissionFlag.UnmanagedCode)
            s.Demand()
        End Sub

    End Module

    - Scott Swigart
    blog: http://ea.3leaf.com

    "Marius Groenendijk" <M (underscore) Groenendijk At (VeryWarm) Mail> wrote
    in message news:eoawkrcvEHA.3612@TK2MSFTNGP09.phx.gbl...
    > Hi group,
    >
    > I want my app to show a msg if my it doesn't have the required
    > permission(s), however this simply doesn't work.
    >
    > What am I overlooking/doing wrong??
    >
    > [VB.NET]
    > Try
    > Dim x As New SecurityPermission(SecurityPermissionFlag.UnmanagedCode)
    > x.Flags = Security.Permissions.SecurityPermissionFlag.UnmanagedCode
    > x.Demand()
    > MessageBox.Show("YES UnmanagedCode permission")
    > Catch ex As Exception
    > MessageBox.Show("NO UnmanagedCode permission")
    > ' application.exit
    > End Try
    >
    > To ensure that my app doesn't have UnmanagedCode permission I run it from
    > a network share. But the app always claims to have unmanaged permission.
    > Trying a pinvoke (=unmanaged) for instance gives a security exception.
    >
    > TIA,
    > Marius.
    >
    >
    >
    >


  • Next message: Novice: "Looking at specifics of bit encryption negotiated during SSL hands"

    Relevant Pages

    • Re: Check for permission does not work
      ... The following sample throws a security ... exception when it demands the UnmanagedCode permission. ... > To ensure that my app doesn't have UnmanagedCode permission I run it from ...
      (microsoft.public.dotnet.languages.vb)
    • Re: How to publish ASPNET web application locating the app files on shared folder
      ... The problem lies in the network location. ... Security Exception ... Impersonate the identity of the user that ASPNET uses to run the app ...
      (microsoft.public.dotnet.framework.aspnet.security)
    • RE: Unhandled exception vs handled (security issue)
      ... If you are able to lauch the app. ... that the Main is never called due to security exception. ... Adding this line would cause the unhandled exception which would ... In the case of app1, the only way to discover what the exception class is, ...
      (microsoft.public.dotnet.security)
    • Re: Apply security permission in class library, fail to call it ou
      ... if there is a permission denied from the OS it should ... You can do something else - try to do a security ... can intercept where the exception comes from. ... to compile in a Debug mode and catch the permission at app level. ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Check for permission does not work
      ... Demands just check the callers on the stack, ... > To ensure that my app doesn't have UnmanagedCode permission I run it from ... > Trying a pinvoke for instance gives a security exception. ...
      (microsoft.public.dotnet.languages.vb)