Einzelnen Beitrag anzeigen

Gast
(Gast)

n/a Beiträge
 
#1

Quotas unter Windows 2000+ auslesen

  Alt 7. Jul 2003, 00:30
Quotas auslesen geht erst ab Windows 2000 aufwärts. Über Windows XP Home habe ich keine Infos. Die Routine benutzt undokumentierte APIs (NT Native API).

Download auch hier: http://assarbad.net/stuff/!export/cquotas.rar
(sonst siehe Attachment).

Der Source ist "Abfall" ich wollte eigentlich mal ein Kommandozeilen-Utility schreiben, mit dem man Quotas setzen kann. Werde ich vielleicht auch noch machen ... aber hier erstmal soweit wie es ist.

Delphi-Quellcode:
begin
  hFile := CreateFileW('\\.\D:', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  if hFile <> INVALID_HANDLE_VALUE then
  try
    fuqi_len := 1 * sizeof(FILE_USER_QUOTA_INFORMATION);
    repeat
      Writeln('Neuer Durchgang');
      if Assigned(fuqi) then
      begin
        FreeMemory(fuqi);
        fuqi_len := fuqi_len * 2;
      end;
      fuqi := GetMemory(fuqi_len);
      ZeroMemory(fuqi, fuqi_len);
      stat := ZwQueryQuotaInformationFile(hFile, @iostat, fuqi, fuqi_len, False, nil, 0, nil, True);
      Writeln(Format('stat = %8.8X', [stat]));

    until (stat = STATUS_NO_MORE_ENTRIES);
    Writeln(Format('iostat.Status = %8.8X', [iostat.Status]));
    Writeln(Format('stat = %8.8X', [stat]));
    tempfuqi := fuqi;
    while True do
    begin
      try
        Writeln('-------------------------------------------------------------------------------');
        Writeln(Format('%20d | %20d | %20d', [tempfuqi.QuotaUsed, tempfuqi.QuotaThreshold, tempfuqi.QuotaLimit]));
        if IsValidSID(Pointer(@tempfuqi.Sid)) then
        begin
          Write('-> valid SID: ');
          bufsize := sizeof(buf);
          buf2size := sizeof(buf2);
          if LookupAccountSid(nil, Pointer(@tempfuqi.Sid), @buf, bufsize, @buf2, buf2size, nameuse) then
            Writeln(string(PChar(@buf2)), '\', string(PChar(@buf)));
        end;
        Write('S-', tempfuqi.Sid.Revision, '-', DWORD(tempfuqi.Sid.IdentifierAuthority.Value[5]) + DWORD(tempfuqi.Sid.IdentifierAuthority.Value[4] shl 8) + DWORD(tempfuqi.Sid.IdentifierAuthority.Value[3] shl 16) + DWORD(tempfuqi.Sid.IdentifierAuthority.Value[2] shl 24));
        for i := 0 to (tempfuqi.SidLength - (sizeof(SID) - sizeof(DWORD))) div sizeof(DWORD) - 1 do
        begin
          Write('-', tempfuqi.Sid.SubAuthority[i]);
        end;
        Writeln;
        if tempfuqi.NextEntryOffset <> 0 then
          tempfuqi := PFILE_USER_QUOTA_INFORMATION(PChar(tempfuqi) + tempfuqi.NextEntryOffset)
        else break;
      except
        Writeln('EXCEPTION!!!');
      end;
    end;
    FreeMemory(fuqi);
  finally
    CloseHandle(hFile);
  end;
  Readln;
end.
Angehängte Dateien
Dateityp: rar cquotas.rar (47,2 KB, 20x aufgerufen)
  Mit Zitat antworten Zitat