Advertisement

06.17.2008 at 11:45AM PDT, ID: 23492776 | Points: 50
[x]
Attachment Details

NtDeleteFile why don't work on a windows application whit Dinamic link to NTDLL.DLL???

Asked by 0x7F in Windows ATL / WTL / COM Programming, Windows Programming

Tags: C\C++ WIN32API

WHY DON'T WORK IS PERFECT! plz helpStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
#define STATUS_SUCCESS 0x00000000L
 
typedef struct _UNICODE_STRING {
	USHORT Length;
	USHORT MaximumLength;
	PWSTR  Buffer;
} UNICODE_STRING;
typedef UNICODE_STRING *PUNICODE_STRING;
typedef const UNICODE_STRING *PCUNICODE_STRING;
 
typedef struct _OBJECT_ATTRIBUTES {
	ULONG Length;
	HANDLE RootDirectory;
	PUNICODE_STRING ObjectName;
	ULONG Attributes;
	PVOID SecurityDescriptor;
	PVOID SecurityQualityOfService;
} OBJECT_ATTRIBUTES;
typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES;
 
typedef NTSTATUS (NTAPI *LPNTDELETEFILE)(IN POBJECT_ATTRIBUTES objectAttributes);
 
 
 
BOOL NtDeleteFileForced(LPTSTR lpszDeletePath) {
	HMODULE hModuleNt;
	NTSTATUS lNtStatus;
	LPNTDELETEFILE NtDeleteFile;
	OBJECT_ATTRIBUTES tagObjectAttributes;
	UNICODE_STRING tagUnicodeString;
	hModuleNt = GetModuleHandle(TEXT("NTDLL.DLL"));
	if (!hModuleNt) {
		return FALSE;
	}
	NtDeleteFile = (LPNTDELETEFILE)GetProcAddress(hModuleNt, "NtDeleteFile");
	if (!NtDeleteFile) {
		return FALSE;
	}
	ZeroMemory(&tagUnicodeString, sizeof(UNICODE_STRING));
	ZeroMemory(&tagObjectAttributes, sizeof(OBJECT_ATTRIBUTES));
	tagUnicodeString.Length = lstrlen(lpszDeletePath);
    tagUnicodeString.MaximumLength = MAX_PATH;
	tagUnicodeString.Buffer = lpszDeletePath;
    tagObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
	tagObjectAttributes.ObjectName = &tagUnicodeString;
	lNtStatus = NtDeleteFile(&tagObjectAttributes);
	if (lNtStatus != STATUS_SUCCESS) {
		return FALSE;
	}
	return TRUE;
}
 
 
int _tmain(int argc, LPCTSTR *argv[]) {
    
	NtDeleteFileForced(TEXT("C:\\TEST\\testing.txt"));
 
	ExitProcess(TRUE);
}
 
Loading Advertisement...
 
[+][-]06.18.2008 at 02:58PM PDT, ID: 21817657

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.18.2008 at 03:58PM PDT, ID: 21817998

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.19.2008 at 03:49AM PDT, ID: 21820915

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.19.2008 at 03:33PM PDT, ID: 21827072

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628