Connecting Tech Pros Worldwide Forums | Help | Site Map

User Privileges

Feldman Alex
Guest
 
Posts: n/a
#1: Nov 17 '05
Hi all,



I need to know the user privileges (does user have administrator privileges)
..

Which c# api's should i use?

Thanks a lot



Willy Denoyette [MVP]
Guest
 
Posts: n/a
#2: Nov 17 '05

re: User Privileges



"Feldman Alex" <utxed94@mail.ru> wrote in message
news:%2301zhkeNFHA.2556@TK2MSFTNGP15.phx.gbl...[color=blue]
> Hi all,
>
>
>
> I need to know the user privileges (does user have administrator
> privileges)
> .
>
> Which c# api's should i use?
>
> Thanks a lot
>
>[/color]
Please define Administrator privileges.
If a user is a member of the administrators group it has the same privileges
as the administrator suposing administrator is also a member, but that
doesn't mean a lot if someone changed the default administrator privileges.

What privilege are you looking for exactly?

Willy.


Feldman Alex
Guest
 
Posts: n/a
#3: Nov 17 '05

re: User Privileges


Well , I'll describe a full task.
I'm writing a install application, and I need to know that the user have the
privileges to install/write to program files.

Thank you
Alex

"Willy Denoyette [MVP]" <willy.denoyette@telenet.be> wrote in message
news:eN3DzzeNFHA.568@TK2MSFTNGP09.phx.gbl...[color=blue]
>
> "Feldman Alex" <utxed94@mail.ru> wrote in message
> news:%2301zhkeNFHA.2556@TK2MSFTNGP15.phx.gbl...[color=green]
> > Hi all,
> >
> >
> >
> > I need to know the user privileges (does user have administrator
> > privileges)
> > .
> >
> > Which c# api's should i use?
> >
> > Thanks a lot
> >
> >[/color]
> Please define Administrator privileges.
> If a user is a member of the administrators group it has the same[/color]
privileges[color=blue]
> as the administrator suposing administrator is also a member, but that
> doesn't mean a lot if someone changed the default administrator[/color]
privileges.[color=blue]
>
> What privilege are you looking for exactly?
>
> Willy.
>
>[/color]


Willy Denoyette [MVP]
Guest
 
Posts: n/a
#4: Nov 17 '05

re: User Privileges



"Feldman Alex" <utxed94@mail.ru> wrote in message
news:ecvoqNfNFHA.1884@TK2MSFTNGP15.phx.gbl...[color=blue]
> Well , I'll describe a full task.
> I'm writing a install application, and I need to know that the user have
> the
> privileges to install/write to program files.
>
> Thank you
> Alex[/color]


By default only administrators and power users have write access privileges
to "Program Files", so you could also check group membership for the current
user.
Something like this should do...
AppDomain ad = Thread.GetDomain();
ad.SetPrincipalPolicy(PrincipalPolicy.WindowsPrinc ipal);
WindowsPrincipal user = (WindowsPrincipal)Thread.CurrentPrincipal;
if(user.IsInRole(WindowsBuiltInRole.Administrator) ||
user.IsInRole(WindowsBuiltInRole.Administrator))
{
// Ok, user is power user or administrator
..
}
else
// Non privileged user, not ok to continue...

Another way to determine the access privileges to a folder, is by creating a
dummy file into the folder, if it fails, it's because the user has no write
access privileges.

Willy.


Feldman Alex
Guest
 
Posts: n/a
#5: Nov 17 '05

re: User Privileges


Thank you Willy
You helped me a lot :)

"Willy Denoyette [MVP]" <willy.denoyette@telenet.be> wrote in message
news:ego6i9fNFHA.508@TK2MSFTNGP12.phx.gbl...[color=blue]
>
> "Feldman Alex" <utxed94@mail.ru> wrote in message
> news:ecvoqNfNFHA.1884@TK2MSFTNGP15.phx.gbl...[color=green]
> > Well , I'll describe a full task.
> > I'm writing a install application, and I need to know that the user have
> > the
> > privileges to install/write to program files.
> >
> > Thank you
> > Alex[/color]
>
>
> By default only administrators and power users have write access[/color]
privileges[color=blue]
> to "Program Files", so you could also check group membership for the[/color]
current[color=blue]
> user.
> Something like this should do...
> AppDomain ad = Thread.GetDomain();
> ad.SetPrincipalPolicy(PrincipalPolicy.WindowsPrinc ipal);
> WindowsPrincipal user = (WindowsPrincipal)Thread.CurrentPrincipal;
> if(user.IsInRole(WindowsBuiltInRole.Administrator) ||
> user.IsInRole(WindowsBuiltInRole.Administrator))
> {
> // Ok, user is power user or administrator
> ..
> }
> else
> // Non privileged user, not ok to continue...
>
> Another way to determine the access privileges to a folder, is by creating[/color]
a[color=blue]
> dummy file into the folder, if it fails, it's because the user has no[/color]
write[color=blue]
> access privileges.
>
> Willy.
>
>[/color]


Closed Thread