|
源码如下:壹‘一键恢复工具’源码,麻烦帮忙看看这源有没有问题?
#AutoIt3Wrapper_Icon=OneKey.ico
#AutoIt3Wrapper_Outfile=OneKey.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Comment=稻田守望者
#AutoIt3Wrapper_Res_Description=Windows 一键恢复
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_Field=QQ:86126720
#AutoIt3Wrapper_Res_Field=啊思专属 提供源码共享
#NoTrayIcon
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
_Singleton("test")
$g_szVersion = "test"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)
If @HomeDrive <> "C:" Then
MsgBox(16 + 0, "错误", "本程序仅支持系统分区在硬盘第一分区。")
Exit
EndIf
$i = 1
$Str = "CDEFGHIJKLMNOPQRSTUVWXYZ"
While $i <= 24
$Str1 = StringLeft($Str, $i)
$Dirve = StringRight($Str1, 1)
$var = DriveGetType($Dirve & ":\")
If FileExists($Dirve & ":\") Then
If $var = "Fixed" Then
$Dirve1 = $Dirve & ":"
EndIf
EndIf
$i = $i + 1
WEnd
$Form1 = GUICreate("Windows 一键恢复", 291, 140, -1, -1)
$Group1 = GUICtrlCreateGroup("Ghost 镜像文件路径:", 15, 40, 260, 55)
$Radio1 = GUICtrlCreateRadio("备份系统", 40, 13, 80, 20)
$Radio2 = GUICtrlCreateRadio("还原系统", 150, 13, 80, 20)
GUICtrlSetState($Radio1, $GUI_CHECKED)
$name = $Dirve1 & "\GHOST\" & @OSVersion & ".GHO"
$Input1 = GUICtrlCreateInput($name, 22, 65, 180, 20)
$Button1 = GUICtrlCreateButton("浏览(&O)", 210, 64, 55, 22, 0)
$Graphic1 = GUICtrlCreateGraphic(8, 5, 275, 100)
GUICtrlSetColor(-1, 0xFFFFFF)
$Button2 = GUICtrlCreateButton("确定(&Y)", 170, 112, 50, 22, 0)
$Button3 = GUICtrlCreateButton("退出(&X)", 230, 112, 50, 22, 0)
$Label1 = GUICtrlCreateLabel("啊思专版 QQ:86126720", 20, 117, 130, 30, 0)
GUICtrlSetColor($Label1, 0xFF0000)
GUICtrlSetTip($Label1, "http://user.qzone.qq.com/86126720")
GUICtrlSetCursor($Label1, 0)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Select
Case $nMsg = $GUI_EVENT_CLOSE
Exit
Case $nMsg = $Button3
Exit
Case $nMsg = $Label1
ShellExecute("http://user.qzone.qq.com/86126720")
Case $nMsg = $Button1
If GUICtrlRead($Radio1) = 1 Then
$path = FileSaveDialog("", "", "Ghost 镜像(*.GHO)", "")
If $path <> "" Then
$Dirve2 = StringLeft($path, 1)
If $Dirve2 = "C" Then
MsgBox(64, "提示", "镜像文件不能保存于系统盘,请重新选择备份路径。")
GUICtrlSetData($Input1, "")
Else
$t = StringInStr($path, ".", 0, -1)
If $t = 0 Then
GUICtrlSetData($Input1, $path & ".GHO")
Else
$kuozhanname = StringTrimLeft($path, $t - 1)
If $kuozhanname = ".GHO" Then
If Not FileExists($path) Then
GUICtrlSetData($Input1, $path)
Else
$ask1 = MsgBox(48 + 4, "警告", "您确定要覆盖" & $path & "吗?")
If $ask1 = 6 Then
GUICtrlSetData($Input1, $path)
EndIf
EndIf
Else
MsgBox(64, " 提示", "您输入的文件名有错。Ghost镜像文件的扩展名必须是 .GHO 。请重新输入。")
GUICtrlSetData($Input1, "")
EndIf
EndIf
EndIf
EndIf
EndIf
If GUICtrlRead($Radio2) = 1 Then
$path = FileOpenDialog("", "", "Ghost 镜像(*.GHO)|所有文件(*.*)", 3, "")
If $path <> "" Then
$Dirve2 = StringLeft($path, 1)
If $Dirve2 = "C" Then
MsgBox(64, "提示", "不能从系统分区恢复Ghsot镜像,请移动 " & $path & " 到其它分区。")
Else
GUICtrlSetData($Input1, $path)
EndIf
EndIf
EndIf
Case $nMsg = $Button2
GUICtrlSetState($Button2, $GUI_DISABLE)
GUICtrlSetState($Button3, $GUI_DISABLE)
If GUICtrlRead($Radio1) = 1 Then
$D = StringLeft(GUICtrlRead($Input1), 1)
$D1 = StringLeft(GUICtrlRead($Input1), 2)
$b = StringInStr($Str, $D)
$M = StringInStr(GUICtrlRead($Input1), ".", 0, -1)
$K = StringInStr(GUICtrlRead($Input1), "\", 0, -1)
$N = StringTrimLeft(GUICtrlRead($Input1), $M - 1)
$L = StringInStr(GUICtrlRead($Input1), "\")
$dir1 = StringLeft(GUICtrlRead($Input1), $K)
If GUICtrlRead($Input1) <> "" Then
$var1 = DriveGetType($D1 & "\")
If FileExists($D1 & "\") And $var1 <> "Removable" And $var1 <> "CDROM" And $var1 <> "Network" And $var1 <> "RAMDisk" And $var1 <> "Unknown" Then
If $D1 = "C:" Then
MsgBox(64, "提示", "镜像文件不能保存于系统盘,请重新选择备份路径。")
GUICtrlSetData($Input1, "")
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
Else
If $N = ".GHO" And StringInStr($Str, $D) <> 0 And StringInStr(GUICtrlRead($Input1), ":") = 2 And $L = 3 And $M - $K <> 1 Then
SplashTextOn("", "程序正在处理...", 200, 30, @DesktopWidth - 230, @DesktopHeight - 70, 32 + 1, "", 12)
If Not FileExists($dir1) Then
DirCreate($dir1)
EndIf
$bakname = StringTrimLeft(GUICtrlRead($Input1), $L)
If FileExists("C:\Ghost.bat") Then
FileSetAttrib("C:\Ghost.bat", "-RSH")
EndIf
$bat1 = FileOpen("C:\Ghost.bat", 2)
FileWrite($bat1, "Ghost.exe -nousb -clone,mode=pdump,src=1:1,dst=1:" & $b & "\" & $bakname & " -sure -fro -rb -z1" & @CRLF)
FileWrite($bat1, "restart")
FileClose($bat1)
FileSetAttrib("C:\Ghost.bat", "+RSH")
If @OSVersion = "WIN_2000" Or @OSVersion = "WIN_2003" Or @OSVersion = "WIN_XP" Then
FileSetAttrib("C:\boot.ini", "-RSH")
If Not (FileExists("C:\boot.bak")) Then
FileCopy("C:\boot.ini", "C:\boot.bak")
FileSetAttrib("C:\boot.bak", "+RSH")
EndIf
IniWrite("C:\boot.ini", "boot loader", "timeout", "0")
IniWrite("C:\boot.ini", "boot loader", "default", "C:\grldr")
IniWrite("C:\boot.ini", "operating systems", "C:\grldr", "一键备份系统")
FileSetAttrib("C:\boot.ini", "+RSH")
EndIf
If FileExists("C:\menu.lst") Then
FileSetAttrib("C:\menu.lst", "-RSH")
FileCopy("C:\menu.lst", "C:\menu.lst.bak")
FileSetAttrib("C:\menu.lst.bak", "+RSH")
EndIf
$lst = FileOpen("c:\menu.lst", 2)
FileWrite($lst, "map --mem /Ghost.ima (fd0)" & @CRLF)
FileWrite($lst, "map --hook" & @CRLF)
FileWrite($lst, "chainloader (fd0)+1" & @CRLF)
FileWrite($lst, "rootnoverify (fd0)" & @CRLF)
FileWrite($lst, "boot")
FileClose($lst)
FileSetAttrib("c:\menu.lst", "+RSH")
If FileExists("C:\grldr") Then
FileSetAttrib("C:\grldr", "-RSH")
FileCopy("C:\grldr", "C:\grldr.bak")
FileSetAttrib("C:\grldr.bak", "+RSH")
EndIf
FileInstall("grldr", "C:\", 1)
If @OSVersion = "WIN_VISTA" Then
$bat = FileOpen(@TempDir & "\_rd.bat", 2)
FileWrite($bat, "reg unload HKLM\BCD00000000" & @CRLF)
FileWrite($bat, "del %temp%\_rd.bat")
FileClose($bat)
Run(@TempDir & "\_rd.bat", "", @SW_HIDE)
Sleep(800)
FileSetAttrib("C:\Boot\BCD", "-RSH")
FileCopy("C:\Boot\BCD", "C:\Boot\BCD.bak")
FileInstall("BCD", "C:\Boot\BCD", 1)
If FileExists("C:\grldr.mbr") Then
FileSetAttrib("C:\grldr.mbr", "-RSH")
FileCopy("C:\grldr.mbr", "C:\grldr.mbr.bak")
FileSetAttrib("C:\grldr.mbr.bak", "+RSH")
EndIf
FileInstall("grldr.mbr", "C:\grldr.mbr", 1)
FileSetAttrib("C:\grldr.mbr", "+RSH")
EndIf
FileInstall("Ghost.exe", "C:\", 1)
FileInstall("Ghost.ima", "C:\", 1)
FileSetAttrib("C:\grldr", "+RSH")
FileSetAttrib("C:\Ghost.exe", "+RSH")
FileSetAttrib("C:\Ghost.ima", "+RSH")
SplashOff()
GUISetState(@SW_HIDE, $Form1)
$ask2 = MsgBox(4, "一键备份", "处理完成! 您是否要立即重启备份系统? " & @CRLF & @CRLF & "单击“是”: 立即重启备份系统。" & @CRLF & "单击“否”: 稍后手动重启备份系统。")
If $ask2 = 6 Then
Shutdown(6)
Else
Exit
EndIf
Else
MsgBox(64, "提示", "请输入完整的Ghost镜像路径。")
GUICtrlSetData($Input1, "")
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
EndIf
EndIf
Else
MsgBox(16 + 0, "错误", "您的输入有误,请重新输入Ghost镜像的路径。")
GUICtrlSetData($Input1, "")
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
EndIf
Else
MsgBox(64, "错误", "Ghost镜像的路径不能为空。")
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
EndIf
EndIf
If GUICtrlRead($Radio2) = 1 Then
$ask3 = MsgBox(4, "提示", "您确定要还原系统吗?")
If $ask3 = 6 Then
$D1 = StringLeft(GUICtrlRead($Input1), 2)
$var1 = DriveGetType($D1 & "\")
If GUICtrlRead($Input1) <> "" Then
If FileExists($D1 & "\") And $var1 <> "Removable" And $var1 <> "CDROM" And $var1 <> "Network" And $var1 <> "RAMDisk" And $var1 <> "Unknown" Then
If FileExists(GUICtrlRead($Input1)) Then
$type = StringInStr(FileGetAttrib(GUICtrlRead($Input1)), "D")
If $type <> 0 Then
MsgBox(64, "错误", "您的输入有误。请输入完整的Ghost镜像路径。")
GUICtrlSetData($Input1, "")
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
Else
If $D1 = "C:" Then
MsgBox(64, "提示", "不能从系统分区恢复Ghsot镜像,请移动 " & GUICtrlRead($Input1) & " 到其它分区。")
GUICtrlSetData($Input1, "")
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
Else
$D = StringLeft(GUICtrlRead($Input1), 1)
$b = StringInStr($Str, $D)
$M = StringInStr(GUICtrlRead($Input1), ".", 0, -1)
$L = StringInStr(GUICtrlRead($Input1), "\")
$path1 = GUICtrlRead($Input1)
If $M = 0 Then
$ask4 = MsgBox(64 + 4, "提示", $path1 & " 不是标准的Ghost镜像文件,您确定要继续吗?")
If $ask4 = 6 Then
$bakname = StringTrimLeft(GUICtrlRead($Input1), $L)
restore()
Else
GUICtrlSetData($Input1, "")
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
EndIf
Else
$kuozhanname = StringTrimLeft($path1, $M - 1)
If $kuozhanname = ".GHO" Then
$bakname = StringTrimLeft(GUICtrlRead($Input1), $L)
restore()
Else
$ask5 = MsgBox(64 + 4, "提示", $path1 & " 不是标准的Ghost镜像文件,您确定要继续吗?")
If $ask5 = 6 Then
$bakname = StringTrimLeft(GUICtrlRead($Input1), $L)
restore()
Else
GUICtrlSetData($Input1, "")
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
EndIf
EndIf
EndIf
EndIf
EndIf
Else
MsgBox(16 + 0, "错误", GUICtrlRead($Input1) & " 不存在,请重新输入。")
GUICtrlSetData($Input1, "")
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
EndIf
Else
MsgBox(16 + 0, "错误", "您的输入有误,请重新输入Ghost镜像的路径。")
GUICtrlSetData($Input1, "")
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
EndIf
Else
MsgBox(64, "错误", "Ghost镜像的路径不能为空。")
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
EndIf
Else
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
EndIf
EndIf
EndSelect
WEnd
Func restore()
SplashTextOn("", "程序正在处理...", 200, 30, @DesktopWidth - 230, @DesktopHeight - 70, 32 + 1, "", 12)
If FileExists("C:\Ghost.bat") Then
FileSetAttrib("C:\Ghost.bat", "-RSH")
EndIf
$bat2 = FileOpen("C:\Ghost.bat", 2)
FileWrite($bat2, "Ghost.exe -nousb -clone,mode=pload,src=1:" & $b & "\" & $bakname & ":1,dst=1:1 -sure -rb" & @CRLF)
FileWrite($bat2, "restart")
FileClose($bat2)
FileSetAttrib("C:\Ghost.bat", "+RSH")
If @OSVersion = "WIN_2000" Or @OSVersion = "WIN_2003" Or @OSVersion = "WIN_XP" Then
FileSetAttrib("C:\boot.ini", "-RSH")
If Not (FileExists("C:\boot.bak")) Then
FileCopy("C:\boot.ini", "C:\boot.bak")
FileSetAttrib("C:\boot.bak", "+RSH")
EndIf
IniWrite("C:\boot.ini", "boot loader", "timeout", "0")
IniWrite("C:\boot.ini", "boot loader", "default", "C:\grldr")
IniWrite("C:\boot.ini", "operating systems", "C:\grldr", "一键还原系统")
FileSetAttrib("C:\boot.ini", "+RSH")
EndIf
If FileExists("C:\menu.lst") Then
FileSetAttrib("C:\menu.lst", "-RSH")
FileCopy("C:\menu.lst", "C:\menu.lst.bak")
FileSetAttrib("C:\menu.lst.bak", "+RSH")
EndIf
$lst = FileOpen("c:\menu.lst", 2)
FileWrite($lst, "map --mem /Ghost.ima (fd0)" & @CRLF)
FileWrite($lst, "map --hook" & @CRLF)
FileWrite($lst, "chainloader (fd0)+1" & @CRLF)
FileWrite($lst, "rootnoverify (fd0)" & @CRLF)
FileWrite($lst, "boot")
FileClose($lst)
FileSetAttrib("c:\menu.lst", "+RSH")
If FileExists("C:\grldr") Then
FileSetAttrib("C:\grldr", "-RSH")
FileCopy("C:\grldr", "C:\grldr.bak")
FileSetAttrib("C:\grldr.bak", "+RSH")
EndIf
FileInstall("grldr", "C:\", 1)
If @OSVersion = "WIN_VISTA" Then
$bat = FileOpen(@TempDir & "\_rd.bat", 2)
FileWrite($bat, "reg unload HKLM\BCD00000000" & @CRLF)
FileWrite($bat, "del %temp%\_rd.bat")
FileClose($bat)
Run(@TempDir & "\_rd.bat", "", @SW_HIDE)
Sleep(800)
FileSetAttrib("C:\Boot\BCD", "-RSH")
FileCopy("C:\Boot\BCD", "C:\Boot\BCD.bak")
FileInstall("BCD", "C:\Boot\BCD", 1)
If FileExists("C:\grldr.mbr") Then
FileSetAttrib("C:\grldr.mbr", "-RSH")
FileCopy("C:\grldr.mbr", "C:\grldr.mbr.bak")
FileSetAttrib("C:\grldr.mbr.bak", "+RSH")
EndIf
FileInstall("grldr.mbr", "C:\grldr.mbr", 1)
FileSetAttrib("C:\grldr.mbr", "+RSH")
EndIf
FileInstall("Ghost.exe", "C:\", 1)
FileInstall("Ghost.ima", "C:\", 1)
FileSetAttrib("C:\grldr", "+RSH")
FileSetAttrib("C:\Ghost.exe", "+RSH")
FileSetAttrib("C:\Ghost.ima", "+RSH")
SplashOff()
GUISetState(@SW_HIDE, $Form1)
$ask6 = MsgBox(4, "一键还原", "处理完成! 您是否要立即重启还原系统? " & @CRLF & @CRLF & "单击“是”: 立即重启还原系统。" & @CRLF & "单击“否”: 稍后手动重启还原系统。")
If $ask6 = 6 Then
Shutdown(6)
Else
Exit
EndIf
EndFunc ;==>restore
我保存后,为什么我点右键编程脚本时会错误呢? |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入
×
|