I just found this complete example project. It shows how to get the integrity label of a file/folder in Windows Vista.
Get Vista integrity label source.
{$APPTYPE CONSOLE}
uses
Dialogs,
JwaVista,
jwaWindows,
JwsclSecureObjects,
JwsclDescriptor,
JwsclMapping,
JwsclAcl,
JwsclTypes,
SysUtils;
var Path : String;
IsDir : Boolean;
SD : TJwSecurityDescriptor;
H : HANDLE;
begin
Path := ParamStr(1);
if not FileExists(Path) and not DirectoryExists(Path) then
exit;
IsDir := not FileExists(Path) and DirectoryExists(Path);
H := CreateFile(
PChar(Path),//LPCTSTR lpFileName,
STANDARD_RIGHTS_READ,//__in DWORD dwDesiredAccess,
0,//__in DWORD dwShareMode,
nil ,//__in LPSECURITY_ATTRIBUTES lpSecurityAttributes,
OPEN_EXISTING,//__in DWORD dwCreationDisposition,
FILE_FLAG_BACKUP_SEMANTICS,//__in DWORD dwFlagsAndAttributes,
0//__in HANDLE hTemplateFile
);
if H = INVALID_HANDLE_VALUE then
RaiseLastOSError;
try
{We could also directly use GetNamedSecurityInfo}
SD := TJwSecureGeneralObject.GetSecurityInfo(H,SE_FILE_OBJECT,
[siDaclSecurityInformation,siLabelSecurityInformation]);
if Assigned(SD) then
begin
if IsDir then
Writeln(SD.DACL.GetTextMap(TJwSecurityFileFolderMapping))
else
Writeln(SD.DACL.GetTextMap(TJwSecurityFileMapping));
end;
if SD.AuditACL.HasMandatoryLabel then
Writeln(SD.AuditACL.MandatoryLabel.SID.GetText);
SD.Free;
except
On E : Exception do
Writeln(E.Message);
end;
CloseHandle(H);
Writeln;
writeln(‘[Hit return]‘);
readln;
end.
There is also a second way to get the integrity label.
{$APPTYPE CONSOLE}
uses
JwaWindows, JwaVista, JwsclSecureObjects, JwsclACL, JwsclTypes;
var F : TJwSecureFileObject;
aLabel : TJwSystemMandatoryAccessControlEntry;
begin
F := TJwSecureFileObject.Create(‘C:\’);
try
aLabel := F.GetMandatoryLabel;
if Assigned(aLabel) then
begin
Writeln(aLabel.GetText());
if aLabel.GetMandatoryLevelType = MandatoryLevelHigh then
writeln(‘High integrity level’);
aLabel.Free;
end;
finally
F.Free;
end;
end.
Leave a reply