Click here to Skip to main content
15,892,537 members
Home / Discussions / C#
   

C#

 
AnswerRe: C#.net stop program early Pin
Dylan Morley30-Aug-11 1:47
Dylan Morley30-Aug-11 1:47 
Something along these lines...

You'd need using statements for System.Threading and System.Security.Principal

C#
[STAThread]
static void Main()
{
    // Set the thread principal to the current windows identity principal
    AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
    Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());

    if (!Thread.CurrentPrincipal.IsInRole("SomeRoleToTest"))
    {
        // Alert the user they need to be granted permissions
    }
    else
    {
        // User has rights, allow mains screen to load
        Application.Run(new MainWindow());
    }
}


So, check for required permissions - if they exist then allow the load sequence to continue. Otherwise, just have your code exit the Main routine and your program execution will end.
GeneralRe: C#.net stop program early Pin
dcof30-Aug-11 3:53
dcof30-Aug-11 3:53 
GeneralRe: C#.net stop program early [modified] Pin
Dylan Morley30-Aug-11 3:59
Dylan Morley30-Aug-11 3:59 
QuestionC#.net active directory options Pin
dcof29-Aug-11 7:33
dcof29-Aug-11 7:33 
AnswerRe: C#.net active directory options Pin
Richard Andrew x6429-Aug-11 11:22
professionalRichard Andrew x6429-Aug-11 11:22 
GeneralRe: C#.net active directory options Pin
dcof29-Aug-11 16:57
dcof29-Aug-11 16:57 
GeneralRe: C#.net active directory options Pin
Richard Andrew x6429-Aug-11 17:00
professionalRichard Andrew x6429-Aug-11 17:00 
QuestionC# low level mouse hook and form events Pin
Ak47AL29-Aug-11 6:21
Ak47AL29-Aug-11 6:21 
AnswerRe: C# low level mouse hook and form events Pin
BillWoodruff29-Aug-11 18:13
professionalBillWoodruff29-Aug-11 18:13 
GeneralRe: C# low level mouse hook and form events Pin
Ak47AL31-Aug-11 5:47
Ak47AL31-Aug-11 5:47 
GeneralRe: C# low level mouse hook and form events Pin
BillWoodruff31-Aug-11 19:11
professionalBillWoodruff31-Aug-11 19:11 
QuestionRegistry Permissions Pin
Zach.Saunders29-Aug-11 4:50
Zach.Saunders29-Aug-11 4:50 
AnswerRe: Registry Permissions Pin
#realJSOP29-Aug-11 5:28
mve#realJSOP29-Aug-11 5:28 
GeneralRe: Registry Permissions [modified] Pin
Zach.Saunders29-Aug-11 6:18
Zach.Saunders29-Aug-11 6:18 
GeneralRe: Registry Permissions Pin
Anthony Mushrow29-Aug-11 7:36
professionalAnthony Mushrow29-Aug-11 7:36 
AnswerRe: Registry Permissions Pin
Abhinav S29-Aug-11 6:51
Abhinav S29-Aug-11 6:51 
AnswerRe: Registry Permissions Pin
Zach.Saunders29-Aug-11 8:34
Zach.Saunders29-Aug-11 8:34 
GeneralRe: Registry Permissions Pin
Anthony Mushrow29-Aug-11 8:48
professionalAnthony Mushrow29-Aug-11 8:48 
GeneralRe: Registry Permissions Pin
Zach.Saunders29-Aug-11 9:04
Zach.Saunders29-Aug-11 9:04 
GeneralRe: Registry Permissions Pin
Anthony Mushrow29-Aug-11 9:24
professionalAnthony Mushrow29-Aug-11 9:24 
GeneralRe: Registry Permissions Pin
Zach.Saunders29-Aug-11 10:47
Zach.Saunders29-Aug-11 10:47 
QuestionC# Button Click - Press and Release Pin
asterix529-Aug-11 1:33
asterix529-Aug-11 1:33 
AnswerRe: C# Button Click - Press and Release Pin
Shameel29-Aug-11 2:02
professionalShameel29-Aug-11 2:02 
GeneralRe: C# Button Click - Press and Release Pin
asterix529-Aug-11 4:06
asterix529-Aug-11 4:06 
GeneralRe: C# Button Click - Press and Release Pin
Shameel29-Aug-11 5:42
professionalShameel29-Aug-11 5:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.