Link to home
Start Free TrialLog in
Avatar of xRootEE
xRootEE

asked on

NtDeleteFile usage

I'm wondering how can I use NtDeleteFile to delete C:\file.txt
It's being called from a Native Application, and the actual return code is something like -10279875....
lpPathName = "\\??\\C:\\file.txt"

Win XP SP2 + WDK 2008
PathNameString.Length = 19;
   PathNameString.Buffer = (WCHAR *)lpPathName;
   PathNameString.MaximumLength = PathNameString.Length+sizeof(WCHAR);
   
   ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
   ObjectAttributes.RootDirectory = NULL;
   ObjectAttributes.ObjectName = &PathNameString;
   ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
   ObjectAttributes.SecurityDescriptor = NULL;
   ObjectAttributes.SecurityQualityOfService = NULL;
   
   errCode = NtDeleteFile(&ObjectAttributes);

Open in new window

Avatar of and235100
and235100
Flag of United Kingdom of Great Britain and Northern Ireland image

Is this being run locally - i.e. not over the network?
These types of errors are normally down to network access-related issues...
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please ignore my comment.
This is more of jkr's field than mine...
Avatar of xRootEE
xRootEE

ASKER

That just works =)
Thank you very much.
BTW, you can simplify that and make it more error proof using
UNICODE_STRING PathNameString;
OBJECT_ATTRIBUTES ObjectAttributes;
 
RtlCreateUnicodeString(&PathNameString,lpPathName);
 
InitializeObjectAttributes( &ObjectAttributes, &PathNameString, OBJ_CASE_INSENSITIVE, NULL, NULL );
 
errCode = NtDeleteFile(&ObjectAttributes);

Open in new window

Avatar of xRootEE

ASKER

Thank you =) That's much better.