WinXP/Win7重启测试程序
本帖最后由 mgj8721 于 2012-9-13 22:34 编辑#RequireAdmin
#NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=exec.ico
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Description=(WinXP/Win7重启测试程序)
#AutoIt3Wrapper_Res_Fileversion=2012.06.12.12
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_LegalCopyright=Copyright 2012
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer%
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#Region AutoIt3Wrapper 预编译参数(常用参数)
;#AutoIt3Wrapper_Run_Tidy= ;脚本整理
;#AutoIt3Wrapper_Run_Obfuscator= ;代码迷惑
;#AutoIt3Wrapper_Run_AU3Check= ;语法检查
;#AutoIt3Wrapper_Run_Before= ;运行前
;#AutoIt3Wrapper_Run_After= ;运行后
#EndRegion AutoIt3Wrapper 预编译参数(常用参数)
#include <file.au3>
#include <Date.au3>
#include <Timers.au3>
#include <Process.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Misc.au3>
#include <ComboConstants.au3>
#include <UpDownConstants.au3>
Opt("GUICloseOnESC", 0) ;1=按下 ESC 将关闭窗口, 0=按下 ESC 将不关闭GUI窗口
Global $Number,$Number2,$Wait,$time
$g_szVersion = "Reboot.exe"
If WinExists($g_szVersion) Then Exit;在运行程序的过程中防止程序有重复运行.
AutoItWinSetTitle($g_szVersion)
If FileExists(@DesktopDir & "\Reboot.lnk") Then
$details = FileGetShortcut(@DesktopDir & "\Reboot.lnk")
If Not StringInStr($details, @ScriptFullPath, 1) Then
FileCreateShortcut(@ScriptFullPath, @DesktopDir & "\Reboot.lnk", @ScriptDir)
EndIf
Else
FileCreateShortcut(@ScriptFullPath, @DesktopDir & "\Reboot.lnk", @ScriptDir)
EndIf
Select
Case $cmdline = 0;如果是程序运行不是带参数,视为用户手动运行该程序!
Call("Config")
Case $cmdline="/s" And $cmdline = 1;通过运行程序添加参数"/S"参数来判断是开机时自动加载运行!
Sleep(8000)
$wait=Int(Number(IniRead(@ScriptDir & "\Report8.ini", "Reboot", "Waiting","5")))
$Number=IniRead(@ScriptDir & "\Report8.ini", "Reboot", "Number","1")
If $Number <> "n" Then $Number=Int(Number($Number))
$Number2=Int(Number(IniRead(@ScriptDir & "\Report8.ini", "Reboot", "Number2","1")))
$time=IniRead(@ScriptDir & "\Report8.ini", "Time", "Test"&$Number2,"1")
IniWrite(@ScriptDir & "\Report8.ini", "Time", "Test"&$Number2,$time&_Now())
$Number2=$Number2+1
Call ("waiting")
Case $cmdline="/a" ;命令行测试,易用于全自动操作!
If $cmdline = 3 Then
If FileExists (@ScriptDir & "\Report8.ini") Then FileDelete (@ScriptDir & "\Report8.ini")
$Number=$cmdline
$Wait=Int(Number($cmdline))
If $Number <> "n" Then
$Number=Int(Number($cmdline))
If $Number > 0 And $Wait >= 5 Then
$Number2="1"
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Test","...")
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Waiting", $wait)
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Number", $Number)
Call ("waiting")
Else
MsgBox(64, "提示", "重启次数要大于零,等待时间不能小于5秒!")
Exit
EndIf
ElseIf $Wait >= 5 Then
$Number2="1"
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Test","...")
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Waiting", $wait)
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Number", $Number)
Call ("waiting")
Else
MsgBox(64, "提示", "运行"&@ScriptName&"程序 等待时间不能小于5秒!")
Exit
EndIf
Else
MsgBox(64, "提示", "运行"&@ScriptName&"程序参数出错!"&@CRLF&"正确参数:"&@CRLF&"如:""/a 10 5""或""/a n 5""")
Exit
EndIf
Case Else
MsgBox(64, "提示", "运行"&@ScriptName&"程序参数出错!"&@CRLF&"正确参数:"&@CRLF&"如:""/a 10 5""或""/a n 5""")
Exit
EndSelect
Func Config()
Local $abc=1,$w,$N
$w=Int(Number(IniRead(@ScriptDir & "\Report8.ini", "Reboot", "Waiting","5")))
$N=IniRead(@ScriptDir & "\Report8.ini", "Reboot", "Number","Error")
#Region ### START Koda GUI section ### Form=c:\users\mgj\desktop\reboot\form1.kxf
$Form1_1 = GUICreate("Reboot Test", 292, 146, -1, -1)
GUISetBkColor(0xC0DCC0)
$Group1 = GUICtrlCreateGroup("", 8, 2, 187, 79)
$Radio1 = GUICtrlCreateRadio("重启测试---无限次", 21, 20, 125, 20)
GUICtrlSetCursor (-1, 0)
$Radio2 = GUICtrlCreateRadio("重启次数:", 21, 48, 73, 20)
GUICtrlSetCursor (-1, 0)
$Input1 = GUICtrlCreateInput("10", 95, 49, 55, 20)
GUICtrlCreateUpdown($Input1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("", 8, 80, 187, 57)
$Radio3 = GUICtrlCreateRadio("等待倒计时(秒)", 21, 99, 105, 25)
GUICtrlSetCursor (-1, 0)
$Input2 = GUICtrlCreateInput("", 128, 103, 55, 20)
GUICtrlCreateUpdown($Input2)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("测试记录", 205, 10, 81, 33)
GUICtrlSetCursor (-1, 0)
$Button2 = GUICtrlCreateButton("开始测试", 205, 58, 81, 33, $BS_DEFPUSHBUTTON)
GUICtrlSetCursor (-1, 0)
$Button3 = GUICtrlCreateButton("退出程序", 205, 106, 81, 33)
GUICtrlSetCursor (-1, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
If $N="n" Or $N="Error" Then
GUICtrlSetState($Input1, $GUI_DISABLE)
GUICtrlSetState($Radio1, $GUI_CHECKED)
Else
$abc=2
GUICtrlSetData($Input1, $N)
GUICtrlSetState($Radio2, $GUI_CHECKED)
EndIf
GUICtrlSetState($Radio3, $GUI_CHECKED)
GUICtrlSetState($Button3, $GUI_FOCUS)
GUICtrlSetData($Input2, $w)
While 1
$nMsg = GUIGetMsg()
Select
Case $nMsg = $GUI_EVENT_CLOSE
;Exit
Case $nMsg = $Button1
Call ("Report")
Case $nMsg = $Button2
If FileExists (@ScriptDir & "\Report8.ini") Then FileDelete (@ScriptDir & "\Report8.ini")
$Wait=Int(Number(GUICtrlRead ($Input2)))
If $Wait >= 5 Then
$Number2="1"
If $abc=2 Then
$Number=Int(Number(GUICtrlRead ($Input1)))
If $Number <= 0 Then
MsgBox(64, "提示", "重启次数 输入错误!")
GUICtrlSetData($Input1, "")
GUICtrlSetState($Input1, $GUI_FOCUS)
Else
GUIDelete()
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Test","...")
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Waiting", $wait)
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Number", $Number)
Call ("waiting")
EndIf
Else
$Number="n"
GUIDelete()
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Test","...")
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Waiting", $wait)
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Number", $Number)
Call ("waiting")
EndIf
Else
MsgBox(64, "提示", "等待时间 不能小于5秒!")
GUICtrlSetData($Input2, "")
GUICtrlSetState($Input2, $GUI_FOCUS)
EndIf
Case $nMsg = $Button3
GUIDelete()
Exit
Case $nMsg = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
GUICtrlSetState($Input1, $GUI_DISABLE)
$abc=1
Case $nMsg = $radio2 And BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
GUICtrlSetState($Input1, $GUI_ENABLE)
$abc=2
EndSelect
WEnd
EndFunc ;==>Config
Func waiting()
Local $test,$abc=1
If $Number=0 Then $Number="n"
$Form1_1 = GUICreate("Reboot Test", 292, 146, -1, -1)
GUISetBkColor(0xC0DCC0)
$Group1 = GUICtrlCreateGroup("", 8, 0, 275, 41)
$Label1 = GUICtrlCreateLabel($Wait&"秒后将重启计算机", 16, 13, 260, 24, $SS_CENTER)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("停止测试", 22, 106, 81, 33)
GUICtrlSetCursor (-1, 0)
$Button2 = GUICtrlCreateButton("暂停测试", 189, 106, 81, 33)
GUICtrlSetCursor (-1, 0)
$Label2 = GUICtrlCreateLabel($Number2&"Out Of"&$Number, 8, 56, 274, 25, $SS_CENTER)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
WinSetOnTop("Reboot Test", "", 1)
If $Number2 > $Number And $Number<>0 Then
$abc=2
$test="Pass"
RegDelete ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\run","Reboot8"); 则删除注册表开机启动项
GUICtrlSetData($Label1, $Number2-1&"次重启测试完成!")
GUICtrlSetData($Label2, $Number2-1&"Out Of"&$Number)
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Test",$Number2-1&"次重启测试完成!")
GUICtrlSetData($Button1, "退出程序")
GUICtrlSetState($Button2, $GUI_DISABLE)
EndIf
Sleep(1000)
$start = Int(TimerInit())
While 1
While 1
If $abc=2 Then
$start = Int(TimerInit())
ExitLoop
EndIf
Sleep(10)
$end = Int(TimerDiff($start))
$e=Int(($Wait*1000-$end)/1000)
If $e <= 0 Then
IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Number2",$Number2)
IniWrite(@ScriptDir & "\Report8.ini", "Time", "Test"&$Number2,_Now()&"===>>")
RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\run","Reboot8","REG_SZ", @ScriptFullPath&" /s");程序放入注册表开机启动中并加/S参数
Shutdown(6);强制重启电脑
Exit
Else
GUICtrlSetData($Label1, $e&"秒后将重启计算机")
ExitLoop
EndIf
WEnd
$Msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
;Exit
Case $msg = $Button1
If $test<>"Pass" Then IniWrite(@ScriptDir & "\Report8.ini", "Reboot", "Test","第 "&$Number2&" 次测试时被手动中断")
RegDelete ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\run","Reboot8"); 则删除注册表开机启动项
Exit
Case $msg = $Button2
If $abc=2 Then
GUICtrlSetData($Button2, "暂停测试")
$abc=1
Else
GUICtrlSetData($Button2, "继续测试")
$abc=2
EndIf
EndSelect
WEnd
EndFunc ;==>waiting
Func Report()
Local $Rep
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Test Report", 390, 235, -1, -1)
GUISetBkColor(0xC0DCC0)
$Edit1=GUICtrlCreateEdit("", 5, 5, 380, 228)
GUICtrlSetBkColor(-1, 0xFFFFE1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$Rep=FileRead(@ScriptDir&"\Report8.ini")
If $Rep="" Then $Rep="没有找到测试记录!"
GUICtrlSetData ($Edit1, $Rep)
WinSetOnTop("Test Report", "", 1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUIDelete()
ExitLoop
EndSwitch
WEnd
EndFunc ;==>Report
页:
[1]