473,320 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Check for permission does not work

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.Unmanage dCode)
x.Flags = Security.Permissions.SecurityPermissionFlag.Unmana gedCode
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.


Nov 21 '05 #1
3 1266
Marius,

Demands just check the callers on the stack, not the current method. If
you're running this from you application's Main method, you'll probably find
the result you expect if you move this code into a separate method that can
be called from Main.

HTH,
Nicole
"Marius Groenendijk" <M (underscore) Groenendijk At (VeryWarm) Mail> wrote
in message news:eo**************@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.Unmanage dCode)
x.Flags = Security.Permissions.SecurityPermissionFlag.Unmana gedCode
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.

Nov 21 '05 #2
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.Unmanage dCode)
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:eo**************@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.Unmanage dCode)
x.Flags = Security.Permissions.SecurityPermissionFlag.Unmana gedCode
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.

Nov 21 '05 #3
Thanks Nicole! That did it.
"Nicole Calinoiu" <calinoiu REMOVETHIS AT gmail DOT com> wrote in message
news:uI*************@TK2MSFTNGP11.phx.gbl...
Marius,

Demands just check the callers on the stack, not the current method. If
you're running this from you application's Main method, you'll probably
find the result you expect if you move this code into a separate method
that can be called from Main.

HTH,
Nicole
"Marius Groenendijk" <M (underscore) Groenendijk At (VeryWarm) Mail> wrote
in message news:eo**************@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.Unmanage dCode)
x.Flags = Security.Permissions.SecurityPermissionFlag.Unmana gedCode
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.


Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Dino | last post by:
dear all, i've created an application for a customer where the customer can upload ..csv-files into a specified ftp-directory. on the server, a php-script, triggered by a cronjob, reads all the...
3
by: AndrewM | last post by:
Hello everyone, I have an asp page with a create folder script fs.CreateFolder(path) When running this on the server I get a Permission denied message as the IUSER account has no write...
4
by: Jason | last post by:
After reading Eugene Bobukh's blog entry about creating custom non-CAS permissions, I developed a few custom permissions to satisfy the needs of an application I'm currently working on. For...
1
by: varunhome | last post by:
Hi, I want to check for the absence of a string in regular expression. For example, if the string is "Error opening file: Permission denied. Aborting.", I want to check for absence of the string...
7
by: Ajit | last post by:
Is there anyway to check for existance of a file on different machine. i.e. we have a data file (text file) thats stored on some other machine as its not to be exposed in case the web server is...
3
by: TK | last post by:
Excuse me for multiple posting because I've posted this message to aspnet.security NG but have not got any response yet. I'm building an ASP.NET application works in Forms Authentication mode...
4
by: Russell Warren | last post by:
I've been having a hard time tracking down a very intermittent problem where I get a "permission denied" error when trying to rename a file to something that has just been deleted (on win32). ...
2
by: Bill Fallon | last post by:
I have a VS2005 VB.Net windows form application deployed to a share drive. The windows explorer security permissions for this application (.exe) file is set for Everyone with List Folder/Read Data...
4
by: xzzy | last post by:
I have a v1.1 web app that works on my local computer. However, running it at the host computer, the following breaks: when a viewer selects a different country, the State dropdown should...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.