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. Database & SysAdmin
  3. Database
  4. Folder Permissions

Folder Permissions

Scheduled Pinned Locked Moved Database
databasequestion
9 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.
  • J Offline
    J Offline
    jonhbt
    wrote on last edited by
    #1

    Hi, I need to find what are the permissions on a specified folder on the computer. I need to do this by using SQL code. Is it possible to create a stored procedure to showthe permissions of a folder? if yes where can I find some examples to follow please or do someone has any examples please? Thanks

    L 1 Reply Last reply
    0
    • J jonhbt

      Hi, I need to find what are the permissions on a specified folder on the computer. I need to do this by using SQL code. Is it possible to create a stored procedure to showthe permissions of a folder? if yes where can I find some examples to follow please or do someone has any examples please? Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      That would be done by executing the ATTRIB command, through the xp_cmdshell, a stored procedure that's blocked for safety.

      EXEC master.dbo.sp_configure 'show advanced options', 1
      RECONFIGURE
      EXEC master.dbo.sp_configure 'xp_cmdshell', 1
      RECONFIGURE
      EXEC xp_cmdshell 'attrib "C:\Program Files"'

      You can read about safety here[^].

      I are troll :)

      modified on Monday, May 25, 2009 2:23 PM

      J 1 Reply Last reply
      0
      • L Lost User

        That would be done by executing the ATTRIB command, through the xp_cmdshell, a stored procedure that's blocked for safety.

        EXEC master.dbo.sp_configure 'show advanced options', 1
        RECONFIGURE
        EXEC master.dbo.sp_configure 'xp_cmdshell', 1
        RECONFIGURE
        EXEC xp_cmdshell 'attrib "C:\Program Files"'

        You can read about safety here[^].

        I are troll :)

        modified on Monday, May 25, 2009 2:23 PM

        J Offline
        J Offline
        jonhbt
        wrote on last edited by
        #3

        Thanks for your reply. how can I modify this to pass the path as a parameter? I am trying to do it but there is no output.

        L 1 Reply Last reply
        0
        • J jonhbt

          Thanks for your reply. how can I modify this to pass the path as a parameter? I am trying to do it but there is no output.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You can encapsulate the commands in a stored procedure like this;

          CREATE PROCEDURE ExecCmd
          @PATH AS VARCHAR(1024)
          AS
          BEGIN
          DECLARE @Command AS VARCHAR(1024)
          SET @Command = REPLACE('attrib ""', '', @PATH)
          EXEC xp_cmdshell @Command
          END

          Calling the stored procedure with a parameter is done like this;

          EXEC ExecCmd 'C:\Program Files'

          Good luck :)

          I are troll :)

          J 1 Reply Last reply
          0
          • L Lost User

            You can encapsulate the commands in a stored procedure like this;

            CREATE PROCEDURE ExecCmd
            @PATH AS VARCHAR(1024)
            AS
            BEGIN
            DECLARE @Command AS VARCHAR(1024)
            SET @Command = REPLACE('attrib ""', '', @PATH)
            EXEC xp_cmdshell @Command
            END

            Calling the stored procedure with a parameter is done like this;

            EXEC ExecCmd 'C:\Program Files'

            Good luck :)

            I are troll :)

            J Offline
            J Offline
            jonhbt
            wrote on last edited by
            #5

            Thaks for the answer. It is working fine for the Program Files path. the strange thing is that it is not working for other folders that I am passing. Is only returning the folder path only, without any R or something else. And these folders have full permissions (Everyone has full permissions). Do you have an idea of what is going wrong? Thanks

            L 1 Reply Last reply
            0
            • J jonhbt

              Thaks for the answer. It is working fine for the Program Files path. the strange thing is that it is not working for other folders that I am passing. Is only returning the folder path only, without any R or something else. And these folders have full permissions (Everyone has full permissions). Do you have an idea of what is going wrong? Thanks

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Sorry, my bad. The ATTRIB command returns the attributes of a file/folder. You don't want the attributes, but the effective permissions per user/windows account. These can be obtained in a similar fashion, using the CACLS command;

              CACLS "C:\Program Files"

              Hope this helps :)

              I are troll :)

              J 1 Reply Last reply
              0
              • L Lost User

                Sorry, my bad. The ATTRIB command returns the attributes of a file/folder. You don't want the attributes, but the effective permissions per user/windows account. These can be obtained in a similar fashion, using the CACLS command;

                CACLS "C:\Program Files"

                Hope this helps :)

                I are troll :)

                J Offline
                J Offline
                jonhbt
                wrote on last edited by
                #7

                Thanks very much. It realy works. Sry for bothering again but if I had to find only the permissions for the current user how could i modify that? only if possible? Thanks again

                L 1 Reply Last reply
                0
                • J jonhbt

                  Thanks very much. It realy works. Sry for bothering again but if I had to find only the permissions for the current user how could i modify that? only if possible? Thanks again

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  I'm afraid that's somewhat harder to do; the effective permissions aren't set for a user, but for different groups of people. That's one of the reasons why we don't check if we got permission to write to a folder, but simply write, relying on the exception-mechanism to warn when there's insufficient rights. The only way of getting the permissions for the user, is checking whether he/she is a member of the groups that get listed. Your user may be a member of multiple groups, so that makes it somewhat more complex. Your user can have read-access for a particular folder, based on the CREATOR OWNER group, but he/she might *also* have write permissions for *that same* folder if he/she's also a member of BUILTIN\Administrators. That means three steps; * Get the permissions for each group on a folder * Check whether the user is part of that group * Add all permissions, for each group that the user is a member of. That's the effective permission for the folder. Good hunting :)

                  I are troll :)

                  J 1 Reply Last reply
                  0
                  • L Lost User

                    I'm afraid that's somewhat harder to do; the effective permissions aren't set for a user, but for different groups of people. That's one of the reasons why we don't check if we got permission to write to a folder, but simply write, relying on the exception-mechanism to warn when there's insufficient rights. The only way of getting the permissions for the user, is checking whether he/she is a member of the groups that get listed. Your user may be a member of multiple groups, so that makes it somewhat more complex. Your user can have read-access for a particular folder, based on the CREATOR OWNER group, but he/she might *also* have write permissions for *that same* folder if he/she's also a member of BUILTIN\Administrators. That means three steps; * Get the permissions for each group on a folder * Check whether the user is part of that group * Add all permissions, for each group that the user is a member of. That's the effective permission for the folder. Good hunting :)

                    I are troll :)

                    J Offline
                    J Offline
                    jonhbt
                    wrote on last edited by
                    #9

                    Thanks again for your help. I will try to follow the steps that you have given me. thanks again thats already a great start.

                    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