VB如何实现NTFS下授权某用户,可读可写权限

gzluzi 2006-03-02 10:45:18
在网上找了一个相关的源码,可是生成EXE的时候提示

SetAccess 这个没有未定义,是什么意思?

是不是要引用哪个库,或者什么,请高手指点一下

代码------------------------------------------------------------

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
...全文
118 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lsftest 2006-03-02
  • 打赏
  • 举报
回复
楼主没看全。。。。。。。。还有很多东西啊,这里仅贴你问的:

Public Sub SetAccess(sUserName As String, sFileName As String, lMask As Long)
Dim lResult As Long ' Result of various API calls.
Dim I As Integer ' Used in looping.
Dim bUserSid(255) As Byte ' This will contain your SID.
Dim bTempSid(255) As Byte ' This will contain the Sid of each ACE in the ACL .
Dim sSystemName As String ' Name of this computer system.

Dim lSystemNameLength As Long ' Length of string that contains
' the name of this system.

Dim lLengthUserName As Long ' Max length of user name.

'Dim sUserName As String * 255 ' String to hold the current user
' name.


Dim lUserSID As Long ' Used to hold the SID of the
' current user.

Dim lTempSid As Long ' Used to hold the SID of each ACE in the ACL
Dim lUserSIDSize As Long ' Size of the SID.
Dim sDomainName As String * 255 ' Domain the user belongs to.
Dim lDomainNameLength As Long ' Length of domain name needed.

Dim lSIDType As Long ' The type of SID info we are
' getting back.

Dim sFileSD As SECURITY_DESCRIPTOR ' SD of the file we want.

Dim bSDBuf() As Byte ' Buffer that holds the security
' descriptor for this file.

Dim lFileSDSize As Long ' Size of the File SD.
Dim lSizeNeeded As Long ' Size needed for SD for file.


Dim sNewSD As SECURITY_DESCRIPTOR ' New security descriptor.

Dim sACL As ACL ' Used in grabbing the DACL from
' the File SD.

Dim lDaclPresent As Long ' Used in grabbing the DACL from
' the File SD.

Dim lDaclDefaulted As Long ' Used in grabbing the DACL from
' the File SD.

Dim sACLInfo As ACL_SIZE_INFORMATION ' Used in grabbing the ACL
' from the File SD.

Dim lACLSize As Long ' Size of the ACL structure used
' to get the ACL from the File SD.

Dim pAcl As Long ' Current ACL for this file.
Dim lNewACLSize As Long ' Size of new ACL to create.
Dim bNewACL() As Byte ' Buffer to hold new ACL.

Dim sCurrentACE As ACCESS_ALLOWED_ACE ' Current ACE.
Dim pCurrentAce As Long ' Our current ACE.

Dim nRecordNumber As Long

' Get the SID of the user. (Refer to the MSDN for more information on SIDs
' and their function/purpose in the operating system.) Get the SID of this
' user by using the LookupAccountName API. In order to use the SID
' of the current user account, call the LookupAccountName API
' twice. The first time is to get the required sizes of the SID
' and the DomainName string. The second call is to actually get
' the desired information.

lResult = LookupAccountName(vbNullString, sUserName, _
bUserSid(0), 255, sDomainName, lDomainNameLength, _
lSIDType)

' Now set the sDomainName string buffer to its proper size before
' calling the API again.
sDomainName = Space(lDomainNameLength)

' Call the LookupAccountName again to get the actual SID for user.
lResult = LookupAccountName(vbNullString, sUserName, _
bUserSid(0), 255, sDomainName, lDomainNameLength, _
lSIDType)

' Return value of zero means the call to LookupAccountName failed;
' test for this before you continue.
If (lResult = 0) Then
MsgBox "Error: Unable to Lookup the Current User Account: " _
& sUserName
Exit Sub
End If

' You now have the SID for the user who is logged on.
' The SID is of interest since it will get the security descriptor
' for the file that the user is interested in.
' The GetFileSecurity API will retrieve the Security Descriptor
' for the file. However, you must call this API twice: once to get
' the proper size for the Security Descriptor and once to get the
' actual Security Descriptor information.

lResult = GetFileSecurityN(sFileName, DACL_SECURITY_INFORMATION, _
0, 0, lSizeNeeded)

' Redimension the Security Descriptor buffer to the proper size.
ReDim bSDBuf(lSizeNeeded)

' Now get the actual Security Descriptor for the file.
lResult = GetFileSecurity(sFileName, DACL_SECURITY_INFORMATION, _
bSDBuf(0), lSizeNeeded, lSizeNeeded)

' A return code of zero means the call failed; test for this
' before continuing.
If (lResult = 0) Then
MsgBox "Error: Unable to Get the File Security Descriptor"
Exit Sub
End If

' Call InitializeSecurityDescriptor to build a new SD for the
' file.
lResult = InitializeSecurityDescriptor(sNewSD, _
SECURITY_DESCRIPTOR_REVISION)

' A return code of zero means the call failed; test for this
' before continuing.
If (lResult = 0) Then
MsgBox "Error: Unable to Initialize New Security Descriptor"
Exit Sub
End If

' You now have the file's SD and a new Security Descriptor
' that will replace the current one. Next, pull the DACL from
' the SD. To do so, call the GetSecurityDescriptorDacl API
' function.

lResult = GetSecurityDescriptorDacl(bSDBuf(0), lDaclPresent, _
pAcl, lDaclDefaulted)

' A return code of zero means the call failed; test for this
' before continuing.
If (lResult = 0) Then
MsgBox "Error: Unable to Get DACL from File Security " _
& "Descriptor"
Exit Sub
End If

全文参考:
http://www.ask321.com/ask27/how191357.htm

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧