|
Listing 6-16 extracted from chapter
Security
Listing 6-15< > Listing 6-17
This listing can be compiled with the command line: csc.exe /target:exe Example_6_16.cs Errors: 0 Warnings: 0
Example_6_16.cs
using System.Security.Principal;
class Program{
static void Main(){
IPrincipal pr = System.Threading.Thread.CurrentPrincipal;
if( pr.IsInRole( @"BUILTIN\Administrators" ) ){
// Here, the principal is an administrator.
}
else
System.Console.WriteLine(
"You must be an administrator to run this program!");
}
}
Copyright Patrick Smacchia 2006 2007
|