我正在尝试获取 Windows 系统应用程序的文件大小。为了对此进行测试,我创建了一个测试应用程序,它试图在 C:\Windows\System32\smss.exe 中获取 smss.exe 的文件大小,但它失败并出现错误:ERROR_FILE_NOT_FOUND。该文件确实存在(我已经检查过)。我还尝试了不同的方法来获取文件大小,包括:FindFirstFile、CreateFile 和 GetFileSizeEx。但都返回相同的错误。我还想阅读文件内容。
我做错了什么?
代码:
// Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <iostream>
__int64 getFileSize(LPWSTR filePath)
{
WIN32_FILE_ATTRIBUTE_DATA fad;
if (!GetFileAttributesEx(filePath, GetFileExInfoStandard, &fad))
{
_tprintf(TEXT("\n CAnt get file size for file %s error %d"), filePath, GetLastError());
return 0;
}
LARGE_INTEGER size;
size.HighPart = fad.nFileSizeHigh;
size.LowPart = fad.nFileSizeLow;
return size.QuadPart;
}
int _tmain(int argc, _TCHAR* argv[])
{
_tprintf(TEXT("File size %d "), getFileSize(L"C:\\Windows\\System32\\smss.exe"));
}
最佳答案
由于您的应用程序是 32 位的,系统 redirects您转到 SysWOW64 的路径,那里没有 smss.exe
。当你发现 Wow64DisableWow64FsRedirection
禁用此重定向,还要考虑使用 64 位程序也可以解决问题。
关于c++ - 在C++中获取Windows系统应用程序的文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24344454/