转载:https://www.iteye.com/blog/univasity-805234 https://blog.51cto.com/velika/1440105
源码:https://files.cnblogs.com/files/Toya/USN.7z
本程序需要管理员权限
1 #include<iostream> 2 #include<stdio.h> 3 #include<string> 4 #include<tchar.h> 5 #include<Windows.h> 6 7 using namespace std; 8 9 bool isNTFS(string path); 10 HANDLE getHandle(string volName); 11 bool createUSN(HANDLE hVol, CREATE_USN_JOURNAL_DATA& cujd); 12 bool getUSNInfo(HANDLE hVol, USN_JOURNAL_DATA& ujd); 13 bool getUSNJournal(HANDLE hVol, USN_JOURNAL_DATA& ujd); 14 bool deleteUSN(HANDLE hVol, USN_JOURNAL_DATA& ujd); 15 16 int main(){ 17 //isNTFS("C:/"); 18 CREATE_USN_JOURNAL_DATA* cujd = new CREATE_USN_JOURNAL_DATA; 19 USN_JOURNAL_DATA* ujd = new USN_JOURNAL_DATA; 20 HANDLE hVol = getHandle("C:"); 21 createUSN(hVol, *cujd); 22 getUSNInfo(hVol, *ujd); 23 getUSNJournal(hVol, *ujd); 24 deleteUSN(hVol, *ujd); 25 system("pause"); 26 return 0; 27 } 28 29 //判断是否是NTFS盘 30 bool isNTFS(string path){//"C:/" 31 char sysNameBuf[MAX_PATH]; 32 int status = GetVolumeInformationA(path.c_str(), 33 NULL, 34 0, 35 NULL, 36 NULL, 37 NULL, 38 sysNameBuf, 39 MAX_PATH); 40 41 if (0 != status){ 42 if (0 == strcmp(sysNameBuf, "NTFS")){ 43 //printf(" 文件系统名 : %s ", sysNameBuf); 44 cout << "盘符:" << path << " 文件系统名:" << sysNameBuf << endl; 45 return true; 46 } 47 else { 48 printf(" 该驱动盘非 NTFS 格式 "); 49 return false; 50 } 51 52 } 53 return false; 54 } 55 56 /** 57 * step 02. 获取驱动盘句柄 58 */ 59 HANDLE getHandle(string volName){ 60 61 char fileName[MAX_PATH]; 62 fileName[0] = '