Click here to Skip to main content
16,008,175 members
Home / Discussions / C#
   

C#

 
Generalabout xml: Pin
skywen16-Sep-04 3:41
skywen16-Sep-04 3:41 
GeneralRe: about xml: Pin
Heath Stewart16-Sep-04 6:26
protectorHeath Stewart16-Sep-04 6:26 
GeneralAuthority problem, I guess... Pin
mcgahanfl16-Sep-04 2:40
mcgahanfl16-Sep-04 2:40 
GeneralRe: Authority problem, I guess... Pin
Stefan Troschuetz16-Sep-04 3:40
Stefan Troschuetz16-Sep-04 3:40 
GeneralRe: Authority problem, I guess... Pin
leppie16-Sep-04 3:41
leppie16-Sep-04 3:41 
GeneralRe: Authority problem, I guess... Pin
Steven Campbell16-Sep-04 6:22
Steven Campbell16-Sep-04 6:22 
GeneralRe: Authority problem, I guess... Pin
Heath Stewart16-Sep-04 6:37
protectorHeath Stewart16-Sep-04 6:37 
GeneralRe: Authority problem, I guess... Pin
Heath Stewart16-Sep-04 6:57
protectorHeath Stewart16-Sep-04 6:57 
Because software must be careful about requiring admin privileges (for example, why should calc.exe require admin privileges), you must be careful about using features that require admin privileges. This includes writing user preferences or data to protected registry hives (like HKEY_LOCAL_MACHINE) or directories (like %WINDIR%), and many more.

If, at times, your software requires admin privileges, either be prepared to catch SecurityException or similar exceptions (the BCL method documentation should state what could be thrown), or use Code Access Security (CAS) - namely the PrincipalPermission, to either declaratively or imperatively demand permissions with a certain group.

A good starting point to learn CAS is Understanding .NET Code Access Security[^] right here on CodeProject. Be sure to follow the links.

So, if you had a method that required Admin privileges (say to enumerate a certain protected DC in Active Directory), you could code your method like so:
[PrincipalPermission(SecurityAction.Demand, Role="Administrators")]
public IEnumerator GetADEnumerator(string path)
{
  // ...
}
Do note that using the PrincipalPermissionAttribute or PrincipalPermission (for declarative security) does require to either hard-code a domain name (i.e., "MYDOMAIN\Domain Admins") or to use a local group where a domain or machine name isn't required).

In these cases, catch exceptions is a better choice (and should be done anyway since calling a protected method using CAS will still throw an exception).

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
GeneralSimple Problem with listview Pin
brunoconde16-Sep-04 2:20
brunoconde16-Sep-04 2:20 
GeneralRe: Simple Problem with listview Pin
sreejith ss nair16-Sep-04 2:39
sreejith ss nair16-Sep-04 2:39 
GeneralDatagrid form steals focus Pin
the last free name16-Sep-04 1:45
the last free name16-Sep-04 1:45 
GeneralRe: Datagrid form steals focus Pin
sreejith ss nair16-Sep-04 2:31
sreejith ss nair16-Sep-04 2:31 
GeneralRe: Datagrid form steals focus Pin
the last free name16-Sep-04 3:33
the last free name16-Sep-04 3:33 
Questionhow to write debug code for nt service(c#) Pin
williamchou16-Sep-04 1:29
williamchou16-Sep-04 1:29 
AnswerRe: how to write debug code for nt service(c#) Pin
mav.northwind16-Sep-04 3:07
mav.northwind16-Sep-04 3:07 
Generaldelete datagird row Pin
Daminda16-Sep-04 1:20
Daminda16-Sep-04 1:20 
GeneralRe: delete datagird row Pin
sreejith ss nair16-Sep-04 2:28
sreejith ss nair16-Sep-04 2:28 
Generalserialization Pin
brain2cpu16-Sep-04 1:07
professionalbrain2cpu16-Sep-04 1:07 
GeneralRe: serialization Pin
turbochimp16-Sep-04 2:58
turbochimp16-Sep-04 2:58 
GeneralRe: serialization Pin
brain2cpu16-Sep-04 3:31
professionalbrain2cpu16-Sep-04 3:31 
Generalwhy DrawString method does not print "\t" Pin
Mikel Fayad15-Sep-04 22:40
Mikel Fayad15-Sep-04 22:40 
GeneralRe: why DrawString method does not print "\t" Pin
sreejith ss nair15-Sep-04 23:23
sreejith ss nair15-Sep-04 23:23 
GeneralRe: why DrawString method does not print "\t" Pin
sreejith ss nair16-Sep-04 0:44
sreejith ss nair16-Sep-04 0:44 
QuestionHow to get Ipv6 address in WinXP Pin
FrankJiao15-Sep-04 21:11
FrankJiao15-Sep-04 21:11 
AnswerRe: How to get Ipv6 address in WinXP Pin
leppie15-Sep-04 22:17
leppie15-Sep-04 22:17 

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.