CopyFile实现文件的复制。函数原型参考MSDN。这个例子是把自己拷贝到系统目录下,并且换一个名字:
1 bool CopyToSysDir()
2 {
3 bool bResult = false;
4 const TCHAR* szExeName = L"test.exe";
5 TCHAR szDestPath[MAX_PATH];
6 TCHAR szSelfPath[MAX_PATH]={0};
7 GetModuleFileName(NULL,szSelfPath,sizeof(szSelfPath));
8 GetSystemDirectory(szDestPath,MAX_PATH);
9 lstrcat(szDestPath,L"\\");
10 lstrcat(szDestPath,szExeName);
11 if(!CopyFile(szSelfPath,szDestPath,FALSE))
12 {
13 cout << "copy failed" << endl;
14 bResult = false;
15 }
16 else
17 {
18 cout << "copy success" << endl;
19 bResult = true;
20 }
21 return bResult;
22 }
|
posted on 2010-02-27 17:23
郭小帅 阅读(464)
评论(0) 编辑 收藏 引用 所属分类:
API