用vc设计系统援救程序
2010-04-03 20:35:51 来源:WEB开发网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*.cabn"+
"copy "+toShortPath(getMyDir())+m_restoreDlg.m_strSeled+" "+toShortPath(m_strWinDir) +"sysbckup
b000.cab n"+
"copy "+toShortPath(getMyDir())+"Autoexec.bak c:Autoexec.bat /Y n"+
toShortPath(m_strWinDir)+"commandscanreg.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("请插入一张软盘,然后按确定键.nn注意:软盘上的所有内容将被删除.",MB_OKCANCEL))
return;
CStdioFile f; //建立包含建立启动盘的命令的批处理文件并执行.
f.Open(getMyDir()+"myTemp.bat", CFile::modeCreate|CFile::modeWrite,NULL);
CString m_strCommand=toShortPath(m_strWinDir)+"commanddeltree /Y a: n"+
toShortPath(m_strWinDir)+"commandsys 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)+"commandscanreg.exe/restore n";
f.WriteString(m_strCommand);
f.Close();
AfxMessageBox("已经成功的创建了援救盘.");
DeleteFile(getMyDir()+"myTemp.bat");
DeleteFile(getMyDir()+"abcdefgh.txt");
}
更多精彩
赞助商链接