blog

枪手亨利

博客园 首页 新随笔 联系 订阅 管理
本文转自 C++Builder 研究 - http://www.ccrun.com/article/go.asp?i=616&d=vg5p15
//---------------------------------------------------------------------------
#include "sfc.h"
// 本工程中需要导入sfc.lib
//---------------------------------------------------------------------------
// 列出所有被保护的文件
void __fastcall ListAllProtectedFile(TStrings *pList)
{
    PROTECTED_FILE_DATA data;
    data.FileNumber = 0;
    while(SfcGetNextProtectedFile(NULL, &data))
    {
        if(data.FileNumber != 0)
        {
            pList->Add(data.FileName);
        }
    }
}
//---------------------------------------------------------------------------
// 判断一个文件是否被保护
bool __fastcall IsFileProtected(String strFile)
{
    WCHAR wszFileName[MAX_PATH];
    MultiByteToWideChar(CP_ACP, 0, strFile.c_str(), -1, wszFileName, MAX_PATH);
    return SfcIsFileProtected(NULL, wszFileName);
}
//---------------------------------------------------------------------------
// 本文来自C++ Builder 研究. http://www.ccrun.com
//---------------------------------------------------------------------------
// 调用举例
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    // ListAllProtectedFile(Memo1->Lines);
    if(IsFileProtected("E:\\Winnt\\system32\\subst1.exe"))
        ShowMessage("被保护了");
    else
        ShowMessage("没有被保护");
}
//---------------------------------------------------------------------------
posted on 2005-11-12 22:03  henry  阅读(192)  评论(0)    收藏  举报