Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Block Windows "Guest" account

Block Windows "Guest" account

Scheduled Pinned Locked Moved C#
testingbeta-testingquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    marca292
    wrote on last edited by
    #1

    Hi, I want to restrict users log on the computer from Windows "Guest" account from starting our application. Our application can be used on XP, Vista and Windows 7. What is wrong with this solution, I get SecurityException when testing from Win7 guest account, I have tried both PrincipalPermission(null, "Guests"); and PrincipalPermission(null, "Guest"); I have also tried to use PrincipalPermission(null, "Administrators"); and then I can use the application from Admin account but not from guest account. static void Main() { AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); PrincipalPermission principalGuest = new PrincipalPermission(null, "Guest"); //Has also tested with "Guests" try { principalGuest.Demand(); } catch (SecurityException e) { //I only want to get this exception if the user is Windows account type "guest" } } Best regards Olof

    R 1 Reply Last reply
    0
    • M marca292

      Hi, I want to restrict users log on the computer from Windows "Guest" account from starting our application. Our application can be used on XP, Vista and Windows 7. What is wrong with this solution, I get SecurityException when testing from Win7 guest account, I have tried both PrincipalPermission(null, "Guests"); and PrincipalPermission(null, "Guest"); I have also tried to use PrincipalPermission(null, "Administrators"); and then I can use the application from Admin account but not from guest account. static void Main() { AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); PrincipalPermission principalGuest = new PrincipalPermission(null, "Guest"); //Has also tested with "Guests" try { principalGuest.Demand(); } catch (SecurityException e) { //I only want to get this exception if the user is Windows account type "guest" } } Best regards Olof

      R Offline
      R Offline
      RobCroll
      wrote on last edited by
      #2

      have you tried?

              WindowsIdentity wi = WindowsIdentity.GetCurrent();
              WindowsPrincipal wp = new WindowsPrincipal(wi);
      
              if (wp.IsInRole(WindowsBuiltInRole.Guest)) return;
      

      Might need a bit more code but that should help

      Architecture is extensible, code is minimal.

      M 1 Reply Last reply
      0
      • R RobCroll

        have you tried?

                WindowsIdentity wi = WindowsIdentity.GetCurrent();
                WindowsPrincipal wp = new WindowsPrincipal(wi);
        
                if (wp.IsInRole(WindowsBuiltInRole.Guest)) return;
        

        Might need a bit more code but that should help

        Architecture is extensible, code is minimal.

        M Offline
        M Offline
        marca292
        wrote on last edited by
        #3

        Hi, thanks for your answer. With this solution I can block users that belong to the Windows Guest group. I want to block user with name guest. The guest account you can turn on/off on windows. I got an answer on another forum string username = Environment.UserName; if (username.ToLower() == "guest") Application.Exit(); One problem is that the application can be used on many different language OS, if we are using chinese OS do we have to translate "guest" to chinese before or is there another way to determine this? We can translate "guest" but it is easy if there is another way to solve it.

        R 1 Reply Last reply
        0
        • M marca292

          Hi, thanks for your answer. With this solution I can block users that belong to the Windows Guest group. I want to block user with name guest. The guest account you can turn on/off on windows. I got an answer on another forum string username = Environment.UserName; if (username.ToLower() == "guest") Application.Exit(); One problem is that the application can be used on many different language OS, if we are using chinese OS do we have to translate "guest" to chinese before or is there another way to determine this? We can translate "guest" but it is easy if there is another way to solve it.

          R Offline
          R Offline
          RobCroll
          wrote on last edited by
          #4

          You'll need to create globalization resource files. There are a number of articles [here] at CodeProject BTW: You'll be doing the support desk a favour if you add a MessageBox notifying "Guest" that they have insufficient permissions to use the application before exiting.

          Architecture is extensible, code is minimal.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups