; Dim Revision As Long
Enable_Privilege (SE_RESTORE_NAME)
nBufferSize = 255
nDomain = 255
Result = LookupAccountName(
vbNullString, OwnerAccountName, _
Sid(0), nBufferSize, szDomainName, nDomain, peUse)
If (Result = 0) Then
MsgBox "LookupAccountName failed with error code " _
& Err.LastDllError
Exit Sub
End If
Result = InitializeSecurityDescriptor(SecDesc, _
SECURITY_DESCRIPTOR_REVISION)
If (Result = 0) Then
MsgBox "InitializeSecurityDescriptor failed with error code " _
& Err.LastDllError
Exit Sub
End If
Result = SetSecurityDescriptorOwner(SecDesc, Sid(0), 0)
If (Result = 0) Then
MsgBox "SetSecurityDescriptorOwner failed with error code " _
& Err.LastDllError
Exit Sub
End If
Result = SetFileSecurity(FileName, OWNER_SECURITY_INFORMATION, _
SecDesc)
If (Result = 0) Then
MsgBox "SetFileSecurity failed with error code " _
& Err.LastDllError
Exit Sub
Else
MsgBox "Owner of " & FileName & " changed to " _
& OwnerAccountName
End If
Disable_Privilege (SE_RESTORE_NAME)
End Sub
Public Function Enable_Privilege(Privilege As String) As Boolean
Enable_Privilege = ModifyState(Privilege, True)
End Function
Public Function Disable_Privilege(Privilege As String) As Boolean
Disable_Privilege = ModifyState(Privilege, False)
End Function
Public Function ModifyState(Privilege As String, _
Enable As Boolean) As Boolean
Dim MyPrives As TOKEN_PRIVILEGES
Dim PrivilegeId As LUID
Dim ptrPriv As Long '' Pointer to Privileges Structure
Dim hToken As Long '' Token Handle
Dim Result As Long '' Return Value
Result = OpenProcessToken(GetCurrentProcess(), _
TOKEN_ADJUST_PRIVILEGES, hToken)
If (Result = 0) Then
Mod