从临时目录中删除Shadow copy dll

时间:2014-07-21 12:25:52

标签: c++ windows dll shadow-copy

我们的许多exe动态加载B.dll。 B.dll在临时文件中复制自身并重新加载%TMP%\ B-.dll。我试图使用此代码将B-.dll标记为删除,但它失败并且#34;访问被拒绝",毫无疑问是因为LoadLibrary调用:

        char ourDllPath[MAX_PATH];
        // ... set ourDllPath to absolute path...

        char tempPath[MAX_PATH];  
        DWORD dwRetVal = GetTempPath(MAX_PATH, tempPath); 
        char shadowPath[MAX_PATH];
        UINT uRetVal = GetTempFileNameA(tempPath, "FOO_", 0, shadowPath);
        BOOL ok = CopyFileA(ourDllPath, shadowPath, false);
        HMODULE hShadowDll = LoadLibraryA(shadowPath);
        typedef int (WINAPI *PRESUMEFOO)();
        PRESUMEFOO onload2 = (PRESUMEFOO)GetProcAddress(hShadowDll,"_Resume_Foo@0");

        BOOL ok2 = DeleteFileA(shadowPath); // Fails with "Access is denied"

然而,根据这里(http://msdn.microsoft.com/en-us/library/windows/desktop/aa363915(v=vs.85).aspx),这应该是可能的:

" DeleteFile函数在关闭时标记要删除的文件。因此,在关闭文件的最后一个句柄之前不会发生文件删除。"

关于如何在Windows服务器操作系统上将当前打开的文件标记为关闭时的任何想法?

0 个答案:

没有答案