f.WriteString(m_strCommand);
f.Close();
WinExec(getMyDir()+"myTemp.bat",SW_HIDE);
CString m_toRbName;
m_toRbName.Format("rb0%d.cab", m_savedNum); //格式化存储文件名.
CTime m_beginTime=CTime::GetCurrentTime();
CTimeSpan m_timeSpan=CTime::GetCurrentTime()-m_beginTime;
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
int delayTime=150/sysInfo.wProcessorLevel; //根据计算机的速度算出大致的完成时间.
while(!CopyFile(m_strWinDir+"\\sysbckup\\rb000.cab",getMyDir()+m_toRbName,0))
{
MSG msg;
if(::PeekMessage(&msg,m_hWnd,0,0,PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
if(!(m_progress.GetPos()>=100))
m_progress.SetPos(100*m_timeSpan.GetSeconds()/delayTime);
m_timeSpan=CTime::GetCurrentTime()-m_beginTime;
}
m_progress.SetPos(100);
AfxMessageBox("已经成功的备份了系统文件");
DeleteFile(getMyDir()+"myTemp.bat");
}
6.为"开始恢复"按钮或菜单项生成一个响应函数:
void CRescueSysDlg::OnBeginRestore()
{
CRestoreDlg m_restoreDlg;
// CRestoreDlg是一个对话框类,用来将用户输入的恢复名称保存在m_restoreDlg.m_strSeled中.
if(IDCANCEL==m_restoreDlg.DoModal())
return;
CStdioFile f; //建立Autoexec.bat和rescueS.bat,将恢复系统的命令写入.
f.Open(getMyDir()+"Autoexec.bat", CFile::modeCreate|CFile::modeWrite,NULL);
CString m_strCommand=(CString)"echo off \n"+"cls \n"+
toShortPath(getMyDir())+"rescueS.bat \n";
f.WriteString(m_strCommand);
f.Close();
f.Open(getMyDir()+"rescueS.bat", CFile::modeCreate|CFile::modeWrite,NULL);
m_strCommand=(CString)"echo off \n"+"cls \n"+
"del "+toShortPath(m_strWinDir)+"\\sysbckup\\*.cab\n"+
"copy "+toShortPath(getMyDir())+m_restoreDlg.m_strSeled+" "+toShortPath(m_strWinDir) +"\\sysbckup\\rb000.cab \n"+
"copy "+toShortPath(getMyDir())+"Autoexec.bak c:\\Autoexec.bat /Y \n"+
toShortPath(m_strWinDir)+"\\command\\scanreg.exe/restore";
f.WriteString(m_strCommand);
f.Close();
CopyFile(getMyDir()+"Autoexec.bak","c:\\Autoexec.bat",0);
CopyFile("c:\\Autoexec.bat",getMyDir()+"Autoexec.bak",0);
CopyFile(getMyDir()+"Autoexec.bat","c:\\Autoexec.bat",0);
if(IDCANCEL==AfxMessageBox("必须重启才能生效,你想现在重启吗?",MB_OKCANCEL))
return;
else
ExitWindowsEx(EWX_REBOOT,NULL);
}
7.为"创建援救盘"按钮或菜单项生成一个响应函数:
void CRescueSysDlg::OnCreatea()
{
if(IDCANCEL==AfxMessageBox("请插入一张软盘,然后按确定键.\n\n注意:软盘上的所有内容将被删除.",MB_OKCANCEL))
return;
CStdioFile f; //建立包含建立启动盘的命令的批处理文件并执行.
f.Open(getMyDir()+"myTemp.bat", CFile::modeCreate|CFile::modeWrite,NULL);
CString m_strCommand=toShortPath(m_strWinDir)+"\\command\\deltree /Y a:\\ \n"+
toShortPath(m_strWinDir)+"\\command\\sys c: a:\n"+
"dir "+getMyDir()+"rescueSys.exe >> "+getMyDir()+"abcdefgh.txt";
f.WriteString(m_strCommand);
f.Close();
WinExec(getMyDir()+"myTemp.bat",SW_HIDE);
CTime m_beginTime=CTime::GetCurrentTime();
CTimeSpan m_timeSpan=CTime::GetCurrentTime()-m_beginTime;
CFileFind finder;
while(!finder.FindFile(getMyDir()+"abcdefgh.txt"))
//如果找到了abcdefgh.txt则说明批处理已经执行完毕.
{
MSG msg;
if(::PeekMessage(&msg,m_hWnd,0,0,PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
if(!(m_progress.GetPos()>=100))
m_progress.SetPos(100*m_timeSpan.GetSeconds()/30);
m_timeSpan=CTime::GetCurrentTime()-m_beginTime;
}
m_progress.SetPos(100);
f.Open("a:\\autoexec.bat", CFile::modeCreate|CFile::modeWrite,NULL);
m_strCommand=(CString)"echo off \n"+"cls \n"+
"copy "+toShortPath(getMyDir())+"*.cab "+toShortPath(m_strWinDir)+"\\sysbckup /Y \n"+
toShortPath(m_strWinDir)+"\\command\\scanreg.exe/restore \n";
f.WriteString(m_strCommand);
f.Close();
AfxMessageBox("已经成功的创建了援救盘.");
DeleteFile(getMyDir()+"myTemp.bat");
DeleteFile(getMyDir()+"abcdefgh.txt");
}
3COME考试频道为您精心整理,希望对您有所帮助,更多信息在http://www.reader8.com/exam/