[已解决]:求助,如何添加一个错误提示
本帖最后由 QQ386263723 于 2014-1-17 08:13 编辑点击 制作iso模式 时如果当前目录有iso文件,就通过继续往下运行,如何当前目录下没有就提示错误。谢谢!#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
Global $sTitle = '自由人制作U盘启动安装程序UD和U+版二合一'
$hGui = GUICreate($sTitle, 380, 405, -1, -1)
GUICtrlCreateLabel("___________________________________________________________________", 0, 216, 400, 12)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetFont(-1, 16, 100, 0, "宋体")
GUICtrlSetState(-1, $GUI_DISABLE)
$info = GUICtrlCreateLabel(" 特别鸣谢:afanpoiuxiehuahere …… 等好友", 16, 380, 380, 21)
GUICtrlSetColor(-1, 0xee3344)
$Button1 = GUICtrlCreateButton("制作iso模式", 24, 320, 89, 33)
$Button2 = GUICtrlCreateButton("格式化U盘", 149, 323, 89, 33)
$Button3 = GUICtrlCreateButton("启动U盘制作", 269, 323, 89, 33)
$Button4 = GUICtrlCreateButton("Autoit3中文网", 275, 100, 90, 33)
$Pic1 = GUICtrlCreatePic("G:\U盘工具\U盘源码\U盘源码 工具\1.jpg", 0, 0, 380, 92)
$Group1 = GUICtrlCreateGroup("Group1", 0, 144, 377, 73)
$Input1 = GUICtrlCreateInput("Input1", 16, 160, 321, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
DllCall('user32.dll', 'int', 'AnimateWindow', 'hwnd', $hGui, 'int', 1000, 'long', 0x40010)
GUISetState()
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Local $isoPath = (@ScriptDir & "\ziyouren.iso")
$title = "UltraISO"
If Not FileExists("c:\fbinst.exe") Then FileInstall("fbinst.exe", "c:\fbinst.exe", 1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
DllCall('user32.dll', 'int', 'AnimateWindow', 'hwnd', $hGui, 'int', 1000, 'long', 0x50010)
GUISetState()
Exit
Case $Button4
ShellExecute("http://www.autoitx.com/index.php")
Case $Button2 ; 归还U盘空间
Case $Button1
FileInstall("c:\Program Files\ziyouren\UltraISO.exe", "c:\UltraISO.exe", 1)
Run("c:\UltraISO.exe")
WinWait("UltraISO")
If Not WinActive("UltraISO") Then WinActivate("UltraISO")
Send("!f")
Send('{{down}{down}')
Send('{enter}')
WinWait("打开 ISO 文件")
If Not WinActive("打开 ISO 文件") Then WinActivate("打开 ISO 文件")
ControlSetText("打开 ISO 文件", "", "Edit1", $isoPath)
Send("!o")
;ControlClick("打开 ISO 文件", "", "Button2") ;Open
WinWait("UltraISO")
If Not WinActive("UltraISO") Then WinActivate("UltraISO")
Send('!B')
Send('{down}{down}{down}')
Send('{enter}')
WinWait('写入硬盘映像')
ControlClick("写入硬盘映像", "", "", "left", 1, 137, 20)
Send('{down}{down}')
Send('{enter}')
MsgBox(49, "", "自由人温馨提示,请插入U盘,确定备份好u盘里的数据后,点击格式化,在点击写入,等待进入条读完启动盘制作成功!")
EndSwitch
WEnd
是不是在Case $Button1 下面添加$search = FileFindFirstFile("ziyouren.iso")
If $search = -1 Then
MsgBox(0, "", "当前目录没有iso文件!", 5)
exit
EndIf FileInstall("c:\Program Files\ziyouren\UltraISO.exe", "c:\UltraISO.exe", 1)这是神马意思?
如果 "c:\Program Files\ziyouren\UltraISO.exe" 本来就存在干嘛还要复制到 C:\ ?直接 Run("c:\Program Files\ziyouren\UltraISO.exe") 不更简单?
检测文件是否存在可以用 FileExists(),如:
If Not FileExists('c:\Program Files\ziyouren\UltraISO.exe') Then Exit MsgBox(48, '', '文件不存在') 我想是在编译好之后,把UltraISO.exe'打包到脚本里面,可以在别人的电脑上运行并释放到c盘,然后运行脚本点击按纽时打开c盘下的UltraISO.exe'浏览到脚本目录下的ziyouren.iso文件,如果脚本当前目录下有ziyouren.iso文件,就不提示,直接通过,继续运行,如果没有ziyouren.iso 就提示错误,我就是想加个错误提示。谢谢! c:\Program Files\ziyouren\UltraISO.exe目录是我正在编译脚本的目录我也可以放在d:\ziyouren\UltraISO.exe 本帖最后由 QQ386263723 于 2014-1-16 15:07 编辑
哎呀:百思不得其解。昨天晚上睡在床上还在想这个事情。原来我怕别人误删UltraISO.exe文件就无法运行了,所以想打包在脚本里面,如果把这一项FileInstall("c:\Program Files\ziyouren\UltraISO.exe", "c:\UltraISO.exe", 1)去掉,不复制直接运行@ScriptDir &"\UltraISO.exe"还是不行,明明有ziyouren.iso文件,为什么 测试时可以通过,但是编译成exe文件后运行,还是提示没有iso文件。不通过?#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
Global $sTitle = '自由人制作U盘启动安装程序UD和U+版二合一'
$hGui = GUICreate($sTitle, 380, 405, -1, -1)
GUICtrlCreateLabel("___________________________________________________________________", 0, 216, 400, 12)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetFont(-1, 16, 100, 0, "宋体")
GUICtrlSetState(-1, $GUI_DISABLE)
$info = GUICtrlCreateLabel(" 特别鸣谢:afan seniors poiuxiehuahere …… 等好友", 16, 380, 380, 21)
GUICtrlSetColor(-1, 0xee3344)
$Button1 = GUICtrlCreateButton("制作iso模式", 24, 320, 89, 33)
$Button2 = GUICtrlCreateButton("格式化U盘", 149, 323, 89, 33)
$Button3 = GUICtrlCreateButton("启动U盘制作", 269, 323, 89, 33)
$Button4 = GUICtrlCreateButton("Autoit3中文网", 275, 100, 90, 33)
$Pic1 = GUICtrlCreatePic("G:\U盘工具\U盘源码\U盘源码 工具\1.jpg", 0, 0, 380, 92)
$Group1 = GUICtrlCreateGroup("Group1", 0, 144, 377, 73)
$Input1 = GUICtrlCreateInput("Input1", 16, 160, 321, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
DllCall('user32.dll', 'int', 'AnimateWindow', 'hwnd', $hGui, 'int', 1000, 'long', 0x40010)
GUISetState()
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Local $isoPath = (@ScriptDir & "\ziyouren.iso")
$title = "UltraISO"
If Not FileExists("c:\fbinst.exe") Then FileInstall("fbinst.exe", "c:\fbinst.exe", 1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
DllCall('user32.dll', 'int', 'AnimateWindow', 'hwnd', $hGui, 'int', 1000, 'long', 0x50010)
GUISetState()
Exit
Case $Button4
ShellExecute("http://www.autoitx.com/index.php")
Case $Button2 ; 归还U盘空间
Case $Button1
$search = FileFindFirstFile("ziyouren.iso")
If $search = -1 Then
MsgBox(0, "", "当前目录没有ziyouren.iso文件!", 5)
Exit
EndIf
Run(@ScriptDir & "\UltraISO.exe")
WinWait("UltraISO")
If Not WinActive("UltraISO") Then WinActivate("UltraISO")
Send("!f")
Send('{{down}{down}')
Send('{enter}')
WinWait("打开 ISO 文件")
If Not WinActive("打开 ISO 文件") Then WinActivate("打开 ISO 文件")
ControlSetText("打开 ISO 文件", "", "Edit1", $isoPath)
Send("!o")
;ControlClick("打开 ISO 文件", "", "Button2") ;Open
WinWait("UltraISO")
If Not WinActive("UltraISO") Then WinActivate("UltraISO")
Send('!B')
Send('{down}{down}{down}')
Send('{enter}')
WinWait('写入硬盘映像')
ControlClick("写入硬盘映像", "", "", "left", 1, 137, 20)
Send('{down}{down}')
Send('{enter}')
MsgBox(49, "", "自由人温馨提示,请插入U盘,确定备份好u盘里的数据后,点击格式化,在点击写入,等待进入条读完启动盘制作成功!")
EndSwitch
WEnd
本帖最后由 QQ386263723 于 2014-1-16 15:06 编辑
郁闷呀!反复测试了一天,终于搞明白了,我还认为代码错误,其实是我的系统出现了问题,重新安装了一下系统,结果编译成exe也通过了。
现在把 U 盘安装工具ud和iso模式二合一版源码上传和大家分享,本人新手所有代码都是出自本人和互联网的知道达人以及http://www.autoitx.com/网站好友、无忧启动论坛的好友,如果有不合适之处,还请老师及朋友指出和改正,谢谢!
另外 有个问题鼠标跟随背景图片有动态效果用au3代码能写出来吗?如图
#NoTrayIcon
#region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=E:\U盘+光盘工具\多功能u盘系统\U 盘维护系统.exe|-1
#AutoIt3Wrapper_outfile=I:\U盘微型系统\U盘fbinst安装工具.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Description=fba文件安装自由人制作
#AutoIt3Wrapper_Res_Fileversion=没有版权QQ:386263723
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_LegalCopyright=seniors
#endregion ;**** 参数创建于 ACNWrapper_GUI ****
#region AutoIt3Wrapper 预编译参数(常用参数)
#AutoIt3Wrapper_UseAnsi=N ;编码
;#AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer% ;自定义资源段
;#AutoIt3Wrapper_Run_Tidy= ;脚本整理
;#AutoIt3Wrapper_Run_Obfuscator= ;代码迷惑
;#AutoIt3Wrapper_Run_AU3Check= ;语法检查
;#AutoIt3Wrapper_Run_Before= ;运行前
;#AutoIt3Wrapper_Run_After= ;运行后
#endregion AutoIt3Wrapper 预编译参数(常用参数)
#cs ____________________________________
Au3 版本:
脚本作者:
Email:
QQ/TM:
脚本版本:
脚本功能:
#ce _______________脚本开始_________________
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <Array.au3>
#include <EditConstants.au3>
#region ### START Koda GUI section ### Form=
Global $sTitle = '自由人制作U盘启动安装程序UD和U+版二合一'
FileInstall("c:\Program Files\fbinst.exe", @TempDir & "\fbinst.exe")
FileInstall("c:\Program Files\ziyouren.jpg", @TempDir & "\ziyouren.jpg")
Global $usl = 0
Global $total = 0
Global $upan = ""
Global $fba = 0
Global $rd =
Global $rdn = $rd
Global $msg = ["■", "■ ■", "■ ■ ■", "■ ■ ■ ■", "■ ■ ■ ■ ■", "■ ■ ■ ■ ■ ■"]
Global $ok = 0
$hGui = GUICreate($sTitle, 400, 400, -1, -1)
GUICtrlCreateLabel("___________________________________________________________________", 0, 216, 400, 12)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetFont(-1, 16, 100, 0, "宋体")
GUICtrlSetState(-1, $GUI_DISABLE)
$info = GUICtrlCreateLabel("特别鸣谢:afan seniors poiuxiehuahere …… 等好友", 16, 380, 380, 21)
GUICtrlSetColor(-1, 0xee3344)
GUICtrlCreatePic(@TempDir & "\1.jpg", 0, 0, 400, 60)
GUICtrlCreateGroup("磁盘选项", 6, 120, 388, 98)
GUICtrlCreateLabel("可移动磁盘选择:", 16, 145, 100, 17)
DllCall('user32.dll', 'int', 'AnimateWindow', 'hwnd', $hGui, 'int', 1000, 'long', 0x40010)
GUISetState()
$List1 = GUICtrlCreateCombo("", 120, 145, 80, 32, $CBS_DROPDOWNLIST)
$selectupan = GUICtrlCreateButton("刷新磁盘列表", 210, 140, 80, 30)
$openupan = GUICtrlCreateButton("打开磁盘", 300, 140, 80, 30)
$emotin = GUICtrlCreateLabel("", 16, 170, 370, 17)
GUICtrlSetBkColor(-1, 0x00000)
GUICtrlSetColor(-1, 0xee3344) ;red
GUICtrlSetFont(-1, 9, 600)
$kongjian = GUICtrlCreateLabel("", 16, 190, 370, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("备份文件选项", 6, 224, 388, 72)
$List2 = GUICtrlCreateCombo("", 16, 250, 365, 32, $CBS_DROPDOWNLIST)
$search = FileFindFirstFile("*.fba")
If $search = -1 Then
MsgBox(0, "", "当前目录没有fba文件,请手动添加fba文件!", 3)
EndIf
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
GUICtrlSetData(-1, $file)
WEnd
FileClose($search)
$fbasize = GUICtrlCreateLabel("安装启动请选择fba文件", 16, 279, 160, 17)
$addfba = GUICtrlCreateButton("手动添加fba文件", 280, 274, 100, 20)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$clearupan = GUICtrlCreateButton("U盘清除启动", 16, 320, 100, 30)
$instupan = GUICtrlCreateButton("U盘安装启动项", 280, 320, 100, 30)
$instiso = GUICtrlCreateButton("制作iso模式", 150, 320, 100, 30)
$djsw = GUICtrlCreateButton("Autoit3中文网", 300, 70, 90, 30)
genxing()
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Local $isoPath = (@ScriptDir & "\ziyouren.iso")
$search = FileFindFirstFile("ziyouren.iso")
If $search = -1 Then
MsgBox(0, "", "当前目录没有ziyouren.iso文件!", 5)
Exit
EndIf
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
DllCall('user32.dll', 'int', 'AnimateWindow', 'hwnd', $hGui, 'int', 1000, 'long', 0x50010)
GUISetState()
FileDelete(@ScriptDir & "\UltraISO.exe")
FileDelete(@TempDir & "\ziyouren.jpg")
FileDelete(@TempDir & "\fbinst.exe")
leave()
Case $djsw
ShellExecute("http://www.autoitx.com/index.php") ;利用本机默认浏览器运行网页。
Case $List1
kongjian()
Case $instiso
FileInstall("c:\Program Files\UltraISO.exe",@ScriptDir & "\UltraISO.exe", 1)
Run(@ScriptDir & "\UltraISO.exe")
WinWait("UltraISO")
If Not WinActive("UltraISO") Then WinActivate("UltraISO")
Send("!f")
Send('{{down}{down}')
Send('{enter}')
WinWait("打开 ISO 文件")
If Not WinActive("打开 ISO 文件") Then WinActivate("打开 ISO 文件")
ControlSetText("打开 ISO 文件", "", "Edit1", $isoPath)
Send("!o")
;ControlClick("打开 ISO 文件", "", "Button2") ;Open
WinWait("UltraISO")
If Not WinActive("UltraISO") Then WinActivate("UltraISO")
Send('!B')
Send('{down}{down}{down}')
Send('{enter}')
WinWait('写入硬盘映像')
ControlClick("写入硬盘映像", "", "", "left", 1, 137, 20)
Send('{down}{down}')
Send('{enter}')
MsgBox(49, "", "自由人温馨提示,点击写入!")
Case $List2
fbas()
Case $selectupan
genxing()
Case $openupan
If $upan <> "" Then
ShellExecute($upan)
EndIf
Case $addfba
wenjian()
Case $clearupan
If GUICtrlRead($List1) = "" Then
MsgBox(0, "", "请选择U盘!", 2)
Else
$YN = MsgBox(49, "警告", "这个操作将会把你的U盘数据全部清空!如确定将" & GUICtrlRead($List1) & "清除ud分区,按确定,否则按取消.")
If $YN == 1 Then
GUISetState(@SW_DISABLE)
AdlibRegister("install")
RunWait(@ComSpec & " /c " & @TempDir & "\fbinst.exe " & GUICtrlRead($List1) & " format --raw--force", "", @SW_HIDE)
AdlibUnRegister("install")
GUISetState(@SW_ENABLE)
GUICtrlSetData($info, "☆ 欢 迎 使 用 ☆")
MsgBox(0, "", "U盘清除启动成功!")
EndIf
EndIf
Case $instupan
If GUICtrlRead($List1) = "" Then
MsgBox(0, "", "请选择U盘!", 2)
Else
If StringInStr(GUICtrlRead($List2), "fba") == 0 Then
MsgBox(0, "", "请选择fba文件!", 2)
Else
If $total < $fba Then
MsgBox(0, "", "您的U盘空间不够安装这个fba文件启动项项目!", 2)
Else
$YN = MsgBox(49, "警告", "这个操作将会把你的U盘数据全部清空!如确定要在" & GUICtrlRead($List1) & "安装启动,按确定,否则按取消.")
If $YN == 1 Then
GUISetState(@SW_DISABLE)
AdlibRegister("install")
RunWait(@ComSpec & " /c " & @TempDir & "\fbinst.exe " & GUICtrlRead($List1) & " format --archive " & GUICtrlRead($List2) & " --force", "", @SW_HIDE)
AdlibUnRegister("install")
GUISetState(@SW_ENABLE)
GUICtrlSetData($info, "☆ 欢 迎 使 用 ☆")
MsgBox(0, "", "安装启动成功!")
EndIf
EndIf
EndIf
EndIf
EndSwitch
WEnd
Func wenjian()
$var = FileOpenDialog("添加fba文件", @ScriptDir & "\", "Fb备份文件(*.fba)", 1)
If @error Then
MsgBox(4096, "", "没有选择文件!")
Else
$var = StringReplace($var, "|", @CRLF)
GUICtrlSetData($List2, $var)
EndIf
EndFunc ;==>wenjian
Func genxing()
$usl = 0
GUICtrlSetData($List1, "")
GetPartionMsg("USB")
If $usl = 0 Then
$rd = $rdn
Else
For $i = 1 To $usl
$rd[$i] = StringUpper($rd[$i])
GUICtrlSetData($List1, $rdn[$i])
Next
EndIf
kongjian()
EndFunc ;==>genxing
Func kongjian()
$upan = ""
If GUICtrlRead($List1) <> "" Then
For $i = 1 To $usl
If GUICtrlRead($List1) == $rdn[$i] Then
$upan = $rd[$i]
$total = DriveSpaceTotal($rd[$i])
$free = DriveSpaceFree($rd[$i])
If $total == $free Then
GUICtrlSetData($emotin, $rdn[$i] & "就是盘符" & $rd[$i] & "磁盘为空,可以放心安装")
Else
GUICtrlSetData($emotin, $rdn[$i] & "就是盘符" & $rd[$i] & "磁盘有内容,请确认内容已经不重要!")
EndIf
GUICtrlSetData($kongjian, "U盘容量:" & CalcG($total) & ",已用空间:" & CalcG($total - $free))
ExitLoop
EndIf
Next
Else
GUICtrlSetData($emotin, "请插入U盘后按刷新磁盘列表!")
GUICtrlSetData($kongjian, "现在还没选择盘符!")
EndIf
EndFunc ;==>kongjian
Func fbas()
$fba = FileGetSize(GUICtrlRead($List2)) / 1048576
GUICtrlSetData($fbasize, "注意fba文件大小: " & CalcG($fba))
EndFunc ;==>fbas
Func leave()
;$YN = MsgBox(49, "退出", "确定要退出吗?")
If $YN == 1 Then
If FileExists(@TempDir & "\fbinst.exe") Then
FileDelete(@TempDir & "\fbinst.exe")
EndIf
If FileExists(@TempDir & "\1.jpg") Then
FileDelete(@TempDir & "\1.jpg")
EndIf
Exit
EndIf
EndFunc ;==>leave
Func install()
If $ok > 5 Then
$ok = 0
EndIf
GUICtrlSetData($info, "耐心等待 " & $msg[$ok])
$ok += 1
EndFunc ;==>install
Func GetPartionMsg($Interface)
$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_LogicalDiskToPartition")
For $objItem In $colItems
$DiskFH = StringLeft(StringRight($objItem.Dependent, 3), 2)
$PartNum = QueryDiskNum($DiskFH)
If StringMid($PartNum, 2, 3) = $Interface Then
$usl += 1
$rdn[$usl] = "(" & StringMid($PartNum, 6)
$rd[$usl] = $DiskFH
EndIf
Next
EndFunc ;==>GetPartionMsg
Func QueryDiskInterface($n)
$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_DiskDrive Where Index=" & $n)
For $objItem In $colItems
Return $objItem.InterfaceType
Next
EndFunc ;==>QueryDiskInterface
Func QueryDiskNum($d)
$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
$colItems = $objWMIService.ExecQuery("Associators of {win32_LogicalDisk.DeviceID='" & $d & "'} where ResultClass = Win32_DiskPartition")
For $colItem In $colItems
Return "(" & QueryDiskInterface($colItem.DiskIndex) & ":hd" & $colItem.DiskIndex & ")"
Next
EndFunc ;==>QueryDiskNum
Func CalcG($n)
If $n < 1024 Then
Return Int($n) & "MB"
ElseIf $n < 1048576 Then
Return Round($n / 1024, 2) & "GB"
EndIf
EndFunc ;==>CalcG
回复 7# QQ386263723
传送门:http://www.autoitx.com/forum.php?mod=viewthread&tid=17705&highlight=%CB%AE%CE%C6 本帖最后由 seniors 于 2014-1-16 09:56 编辑
这个源码,明明是我在无忧首发的,感谢列表中却没有我。
无忧地址:http://bbs.wuyou.com/forum.php?mod=viewthread&tid=145121
论坛里好多U盘工具,应该多是从这演变来的 回复 8# zcx880517
此楼正解,afan大神早就搞定,还被老外引用。 其实UltraISO支持命令行模式的,干嘛非要模拟点击啊~
页:
[1]