如题!!

解决方案 »

  1.   

    【VB声明】
      Private Declare Function SetFileSecurity Lib "advapi32.dll" Alias "SetFileSecurityA" (ByVal lpFileName As String, ByVal SecurityInformation As Long, pSecurityDescriptor As SECURITY_DESCRIPTOR) As Long【别名】
      SetFileSecurityA
      

  2.   

    完整代码:
    http://www.tek-tips.com/gviewthread.cfm/lev2/4/lev3/32/pid/711/qid/460090
      

  3.   

    '1. Create a Standard EXE project in Visual Basic. Form1 is created by default.
    '2. Add two Textboxes (Text1 and Text2) and two CommandButtons (Command1 and Command2) to Form1.
    '3. Add the following code to the form and the module
    '4. Run the application.
    '5. In the Test1 TextBox, enter the name of the folder you want to change permissions on. (D:\test is entered by default.)
    '    In the Test2 Textbox, enter the name of the user you want to give these permissions to.
    '6. Click the Add & Read permissions button to give Add & Read permissions to the folder, or click the Change Permissions
    '    button to give Change permissions to the folder.
    '7. To check the permissions on the folder, right-click Explorer. Select the Properties menu item, and click the Security
    '    Tab of the Properties dialog box. On the Security tab, click the Permissions button. The specific account should say
    '    Add & Read or Change depending on which button you clicked in the preceding sample.'Add this code to the form
    Private Sub Command1_Click()
       Dim sUserName As String
       Dim sFolderName As String
       sUserName = Trim$(CStr(Text2.Text))
       sFolderName = Trim$(CStr(Text1.Text))
       SetAccess sUserName, sFolderName, GENERIC_READ Or GENERIC_EXECUTE Or DELETE Or GENERIC_WRITE
    End Sub
    Private Sub Command2_Click()
       Dim sUserName As String
       Dim sFolderName As String
       sUserName = Trim$(Text2.Text)
       sFolderName = Trim$(Text1.Text)
       SetAccess sUserName, sFolderName, GENERIC_EXECUTE Or GENERIC_READ
    End Sub
    Private Sub Form_Load()
       Text1.Text = "enter folder name"
       Text2.Text = "enter username"
       Command1.Caption = "Change"
       Command2.Caption = "Read && Add"
    End Sub'Add this code to a module' Constants used within our API calls. Refer to the MSDN for more
    ' information on how/what these constants are used for.' Memory constants used through various memory API calls.
    Public Const GMEM_MOVEABLE = &H2
    Public Const LMEM_FIXED = &H0
    Public Const LMEM_ZEROINIT = &H40
    Public Const LPTR = (LMEM_FIXED + LMEM_ZEROINIT)
    Public Const GENERIC_READ = &H80000000
    Public Const GENERIC_ALL = &H10000000
    Public Const GENERIC_EXECUTE = &H20000000
    Public Const GENERIC_WRITE = &H40000000' The file/security API call constants.
    ' Refer to the MSDN for more information on how/what these constants
    ' are used for.
    Public Const DACL_SECURITY_INFORMATION = &H4
    Public Const SECURITY_DESCRIPTOR_REVISION = 1
    Public Const SECURITY_DESCRIPTOR_MIN_LENGTH = 20
    Public Const SD_SIZE = (65536 + SECURITY_DESCRIPTOR_MIN_LENGTH)
    Public Const ACL_REVISION2 = 2
    Public Const ACL_REVISION = 2
    Public Const MAXDWORD = &HFFFFFFFF
    Public Const SidTypeUser = 1
    Public Const AclSizeInformation = 2'  The following are the inherit flags that go into the AceFlags field
    '  of an Ace header.Public Const OBJECT_INHERIT_ACE = &H1
    Public Const CONTAINER_INHERIT_ACE = &H2
    Public Const NO_PROPAGATE_INHERIT_ACE = &H4
    Public Const INHERIT_ONLY_ACE = &H8
    Public Const INHERITED_ACE = &H10
    Public Const VALID_INHERIT_FLAGS = &H1F
    Public Const DELETE = &H10000' Structures used by our API calls.
    ' Refer to the MSDN for more information on how/what these
    ' structures are used for.
    Type ACE_HEADER
      AceType As Byte
      AceFlags As Byte
      AceSize As Integer
    End Type
    Public Type ACCESS_DENIED_ACE
     Header As ACE_HEADER
     Mask As Long
     SidStart As Long
    End TypeType ACCESS_ALLOWED_ACE
      Header As ACE_HEADER
      Mask As Long
      SidStart As Long
    End TypeType ACL
      AclRevision As Byte
      Sbz1 As Byte
      AclSize As Integer
      AceCount As Integer
      Sbz2 As Integer
    End TypeType ACL_SIZE_INFORMATION
      AceCount As Long
      AclBytesInUse As Long
      AclBytesFree As Long
    End TypeType SECURITY_DESCRIPTOR
      Revision As Byte
      Sbz1 As Byte
      Control As Long
      Owner As Long
      Group As Long
      sACL As ACL
      Dacl As ACL
    End Type
      

  4.   

    http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20226840.html