“PE下粗略判断某个分区是否是Windows系统盘”等价于“PE下某个分区中根目录下是否含有Windows文件夹”。代码如下:
#include<IOSTREAM.H>
#include <WINDOWS.H>
#include <TCHAR.H>
#include <STDIO.H>
#define MAX_PATH 260
bool FindWindows(char szLetter)
{
LPTSTR lpDstWinPath = NULL ;
DWORD dwRet = 0 ;
bool bReturn = false ;
lpDstWinPath = (LPTSTR)malloc(sizeof(char)*MAX_PATH);
sprintf(lpDstWinPath,"%c:\\WINDOWS",szLetter);
dwRet = GetFileAttributes(lpDstWinPath);
if ( dwRet != INVALID_FILE_ATTRIBUTES )
{
if (dwRet&FILE_ATTRIBUTE_DIRECTORY)
{
bReturn = true ; //存在且是文件夹
}
else
{
bReturn = false ;
goto exit;
}
}
else
{
bReturn = false ;
goto exit;
}
exit:
if (lpDstWinPath)
{
free(lpDstWinPath);
}
return bReturn;
}
void main()
{
bool bRet = false;
bRet = FindWindows('d');
if (bRet)
{
cout<<"right"<<endl;
}
}