Runtime Security Permissions


J

Jess.Albert

Hey All,
I've got a program running on a Network share. It works without any
problems when I add the \\server\* with Full Trust in the .Net
Configuration MMC. I also export this security set as an MSI to be
installed for users who wish to run the program.

The question is, is that sometimes a user will simply go to the share
and try running the program sometimes (start -> run ->
\\server\share\Program.Net.Exe). This will cause the application to
fail, and an unfriendly message to be displayed.

I would like to do a test to make sure the program has the correct
permissions to run, but it doesn't even reach the On_Load event. How
would I go about testing to make sure the program is able to run so if
they don't have the security permissions to run a program from the
share, I'd like to give them a nice friendly "Don't Panic!" message :)

Any examples in VB/C# work for me, thanks in advance!

-Jesse Albert
 
Ad

Advertisements

M

Marius Groenendijk

Hi Jesse, here's something in VB that works just fine.
HTH,
Marius.

<snip>
Imports System.Security

Public Class MainApp

Public Shared Sub Main()
If Panic() Then
MessageBox.Show("Don't Panic")
Else
Application.Run(New MainForm)
End If
End Sub

Private Shared Function Panic() As Boolean
Try
Dim trust As New
PermissionSet(Permissions.PermissionState.Unrestricted)
trust.Demand()
Return False
Catch ex As SecurityException
MessageBox.Show("Panic! No permissions to run app")
Return True
Catch ex As Exception
MessageBox.Show("Panic! Trouble running app")
Return True
End Try
End Function
End Class
</snip>
 
Ad

Advertisements

J

Jess.Albert

Perfect, thanks a ton!!!

-Jesse

Hi Jesse, here's something in VB that works just fine.
HTH,
Marius.

<snip>
Imports System.Security

Public Class MainApp

Public Shared Sub Main()
If Panic() Then
MessageBox.Show("Don't Panic")
Else
Application.Run(New MainForm)
End If
End Sub

Private Shared Function Panic() As Boolean
Try
Dim trust As New
PermissionSet(Permissions.PermissionState.Unrestricted)
trust.Demand()
Return False
Catch ex As SecurityException
MessageBox.Show("Panic! No permissions to run app")
Return True
Catch ex As Exception
MessageBox.Show("Panic! Trouble running app")
Return True
End Try
End Function
End Class
</snip>
 

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