delphi 强制删除文件 ZwDeleteFile


本文整理自网络,侵删。

  ZwDeleteFile删文件..........

const
OBJ_CASE_INSENSITIVE = $00000040;
STATUS_SUCCESS = $00000000;

type
NTSTATUS= DWORD;
PVOID= Pointer;

PUnicodeString = ^TUnicodeString;
TUnicodeString = packed record
Length: Word;
MaximumLength: Word;
Buffer: PWideChar;
end;
UNICODE_STRING = TUnicodeString;
PUNICODE_STRING = ^UNICODE_STRING;

POBJECT_ATTRIBUTES = ^TOBJECT_ATTRIBUTES;
TOBJECT_ATTRIBUTES = record
Length: Cardinal;
RootDirectory: THANDLE;
ObjectName: PUNICODE_STRING;
Attributes: Dword;
SecurityDescriptor: pointer; // Points to type SECURITY_DESCRIPTOR
SecurityQualityOfService: pointer; // Points to type SECURITY_QUALITY_OF_SERVICE
end;

procedure RtlInitUnicodeString (var Buffer: TUnicodeString;Source: PWideChar); stdcall;external 'ntdll.dll';
function ZwDeleteFile(ObjectAttributes :POBJECT_ATTRIBUTES): NTSTATUS; stdcall;external 'ntdll.dll';



procedure InitializeObjectAttributes(pAttributes: POBJECT_ATTRIBUTES; n: PUNICODE_STRING;
a: Cardinal; r: THANDLE; s: pointer);
begin
pAttributes^.Length := SizeOf(TOBJECT_ATTRIBUTES);
pAttributes^.RootDirectory := r;
pAttributes^.Attributes := a;
pAttributes^.ObjectName := n;
pAttributes^.SecurityDescriptor := s;
pAttributes^.SecurityQualityOfService := nil;
end;



procedure TForm1.Button1Click(Sender: TObject);
var
at:UNICODE_STRING;
oa:TOBJECT_ATTRIBUTES;
begin
RtlInitUnicodeString(at,'\??\d:\1.sys');
InitializeObjectAttributes(@oa,@at,OBJ_CASE_INSENSITIVE,0,0);
ZwDeleteFile(@oa);
end;

相关阅读 >>

Delphi xe5 json与Delphi object的互换

Delphi固定窗口大小

Delphi日期函数、日期加减

Delphi 使用onvalidate事件或onvalidating事件验证在输入字段(tedit)中输入的值

Delphi xe5 android 黑屏的临时解决办法

Delphi ioutils tdirectory获取一个目录下所有文件名,包括子目录

Delphi 取得任意程序的命令行

Delphi xe android下让tmemo不自动弹出键盘

Delphi idwhois1 简单的用法

Delphi 中的文件系统进行unicode标准化

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...