1 /* 2 获取系统目录,并保存在文件里 3 [peoject->set->link->project chose->subsystem:console] 4 */ 5 #include6 int main(int argc,TCHAR argv[]) 7 { 8 //文件句柄 9 HANDLE hFile;10 DWORD dwWritten;11 //字符数组,用于存储系统目录12 TCHAR szSystemDir[MAX_PATH];13 //获取系统目录14 GetSystemDirectory(szSystemDir,MAX_PATH);15 16 //创建文件17 hFile=CreateFile("systemroot.txt",18 GENERIC_WRITE,19 0,NULL,CREATE_ALWAYS,20 FILE_ATTRIBUTE_NORMAL,21 NULL);22 //判断文件是否创建成功23 if(hFile!= INVALID_HANDLE_VALUE)24 {25 //write systemRoot into file26 if(!WriteFile(hFile,szSystemDir,lstrlen(szSystemDir),&dwWritten,NULL))27 {28 return GetLastError();29 }30 }31 //close file and return32 CloseHandle(hFile);33 return 0;34 }