views:

61

answers:

4

Hi,

I have a winForm application and I want to know of a guest user is running it. how can I know it by c# code?

Thanks.

+2  A: 
if (System.Security.Principal.WindowsIdentity.GetCurrent().IsGuest == true)
   {
     //User is Guest
   }
Barry
A: 

That would depend entirely on how your users are setup. You could use group membership to determine if a user is a Guest or they might be using the Guest account (although some organisations might disable that one).

Dan Iveson
+3  A: 

Here's an optimized version of what Barry said.

   if (System.Security.Principal.WindowsIdentity.GetCurrent().IsGuest)
   {
     //User is Guest
   }
this. __curious_geek
A: 

Are you using Domain Auth? If you are using Domain Auth, get the current user details with

Environment.UserName or Enviroenment.UserDomainName;

and check if user is a member or not.

Serkan Hekimoglu