final int infoType = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
DACL_SECURITY_INFORMATION;
final IntByReference lpnSize = new IntByReference();
boolean succeeded = Advapi32.INSTANCE.GetFileSecurity(
new WString(absoluteFilePath),
infoType,
null,
0, lpnSize);
if (!succeeded) {
final int lastError = Kernel32.INSTANCE.GetLastError();
if (W32Errors.ERROR_INSUFFICIENT_BUFFER != lastError) {
throw new Win32Exception(lastError);
}
}
final int nLength = lpnSize.getValue();
final Memory securityDescriptorMemoryPointer = new Memory(nLength);
succeeded = Advapi32.INSTANCE.GetFileSecurity(new WString(
absoluteFilePath), infoType, securityDescriptorMemoryPointer, nLength, lpnSize);
if (!succeeded) {
securityDescriptorMemoryPointer.clear();
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());