相关疑难解决方法(0)

如何使用Delphi测试目录是否可写?

目前我使用这个函数,基于JCL代码,工作正常:

function IsDirectoryWriteable(const AName: string): Boolean;
var
  FileName: PWideChar;
  H: THandle;
begin
  FileName := PWideChar(IncludeTrailingPathDelimiter(AName) + 'chk.tmp');

  H := CreateFile(FileName, GENERIC_READ or GENERIC_WRITE, 0, nil,
    CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY or FILE_FLAG_DELETE_ON_CLOSE, 0);

  Result := H <> INVALID_HANDLE_VALUE;

  DeleteFile(FileName);
end;
Run Code Online (Sandbox Code Playgroud)

我可以用旗帜改进吗?可以在不实际创建文件的情况下完成测试吗?或者这个功能甚至已经在其中一个RTL或Jedi库中提供了?

windows delphi directory permissions

10
推荐指数
2
解决办法
8390
查看次数

如何以编程方式检查修改权限?

如何以编程方式检查文件夹的创建文件权限?修改文件权限?删除文件权限?
GetNamedSecurityInfo返回我可以写入,C:\Program Files但UAC说Access Denied (5)
我如何有效地确定访问权限?

我的代码:

function GetAccessRights(const FileName: String; ObjectType: SE_OBJECT_TYPE; 
  var Access: Cardinal): Cardinal;
var
  SecDesc: PSECURITY_DESCRIPTOR;
  pDacl: PACL;
  Trusteee: TRUSTEE_;
begin
  result := GetNamedSecurityInfo(PChar(FileName), ObjectType, 
    DACL_SECURITY_INFORMATION, nil, nil, @pDacl, nil, SecDesc);
  if ERROR_SUCCESS = result then
  begin
    // the pDacl may be NULL if the object has unrestricted access
    if pDacl <> nil then
    begin
      with Trusteee do
      begin
        pMultipleTrustee := nil;
        MultipleTrusteeOperation := NO_MULTIPLE_TRUSTEE;
        TrusteeForm := TRUSTEE_IS_NAME;
        TrusteeType := TRUSTEE_IS_UNKNOWN;
        ptstrName …
Run Code Online (Sandbox Code Playgroud)

delphi uac file-permissions

6
推荐指数
1
解决办法
4800
查看次数

标签 统计

delphi ×2

directory ×1

file-permissions ×1

permissions ×1

uac ×1

windows ×1