[已解决] AutoIt v3.3.16.1编译的程序PE下运行format命令无法格式化C盘。
本帖最后由 令狐大虾 于 2023-4-24 12:12 编辑AutoIt v3.3.16.1版本编译后无法正常格式化(重要的事说三遍,请用AutoIt v3.3.16.1编译测试),一闪而过。AutoIt_v3.3.14.5+R_4.1.0_Setup编译之前是正常运行的。一下是缩略代码演示,劳烦各位大大帮忙看看
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1_1 = GUICreate('64PE多合一系统安装器 By 令狐大虾', 443, 265)
$Button1 = GUICtrlCreateButton('1、Windows 7 SP1 Ultimate', 5, 20, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button2 = GUICtrlCreateButton('2、Windows 10 Enterprise', 5, 70, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button3 = GUICtrlCreateButton('3、Windows 11 Enterprise', 5, 120, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button4 = GUICtrlCreateButton('4、Mbr启动引导修复程序 ', 5, 170, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button5 = GUICtrlCreateButton('5、Windows Server2008r2SP1',228, 20, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button6 = GUICtrlCreateButton('6、Windows Server 2019', 228, 70, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button7 = GUICtrlCreateButton('7、Windows Server 2022', 228, 120, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button8 = GUICtrlCreateButton('8、ESP分区挂载及引导修复程序',228, 170, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button9 = GUICtrlCreateButton('使用说明', 195, 220, 55, 30)
$Label1= GUICtrlCreateLabel('', 8, 228, 175, 30, $BS_LEFT)
$Label2= GUICtrlCreateLabel('QQ:425283 微信:D286688496', 265, 228, 175, 30, $BS_LEFT)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
;============================================================================================================================
Case $Button1;1、Windows 7 SP1 Ultimate
$msg = MsgBoxE(3+64, '','Windows 7 SP1 Ultimate 可选全自动安装程序'&@CRLF&@CRLF&'警告:程序将格式化C盘、请预先备份好资料、并确认PE下C盘为可安装系统分区后再运行!', 0, '', '常规版', '魔改版', '退出', '',0)
Select
Case $msg = 6
RunWait(@ComSpec & ' /c ' & 'format c:/fs:ntfs /q /x /y');==>格式化C盘
Case $msg = 7
Case $msg = 2
;==>退出
EndSelect
;============================================================================================================================
Case $Button2 ;2、Windows 10 Enterprise
;============================================================================================================================
Case $Button3 ;3、Windows 11 Enterprise
;============================================================================================================================
Case $Button4 ;4、Mbr启动引导修复程序
;============================================================================================================================
Case $Button5;5、Windows Server 2008 r2 SP1
;============================================================================================================================
Case $Button6 ;6、Windows Server 2019
;============================================================================================================================
Case $Button7 ;Windows Server 2022
;============================================================================================================================
Case $Button8 ;ESP分区挂载及引导修复程序
;============================================================================================================================
Case $Button9 ;9、使用说明
;============================================================================================================================
EndSwitch
WEnd
;复制进度条
Func _DirCopy($SourceDir,$Destdir)
Local $Shell
Local $FOF_SIMPLEPROGRESS = 16
If Not FileExists($Destdir) Then DirCreate($Destdir)
$Shell = ObjCreate("shell.application")
$Shell.namespace($Destdir).CopyHere($SourceDir,$FOF_SIMPLEPROGRESS)
EndFunc
;总体$msg = MsgBoxE 位置和文字
Func MsgBoxE($flag, $title, $text, $timeout = 0, $hwnd = '', $Button1 = '', $Button2 = '', $Button3 = '', $x = '', $y = '')
; 参数加在 title 后面传递给 MB__CallBack,避免使用全局变量
$title &= @CRLF & 'B1=' & $Button1 & @CRLF & 'B2=' & $Button2 & @CRLF & 'B3=' & $Button3 & @CRLF & 'x=' & $x & @CRLF & 'y=' & $y
Local $hGUI = GUICreate("")
Local $sFuncName = "GetWindowLongW"
If @AutoItX64 Then $sFuncName = "GetWindowLongPtrW"
Local $aResult = DllCall("user32.dll", "long_ptr", $sFuncName, "hwnd", $hGUI, "int", -6)
Local $hInst = $aResult
$aResult = DllCall("kernel32.dll", "dword", "GetCurrentThreadId")
Local $iThreadId = $aResult
Local $hCallBack = DllCallbackRegister("MB__CallBack", "int", "int;hWnd;ptr")
Local $pCallBack = DllCallbackGetPtr($hCallBack)
$aResult = DllCall("user32.dll", "handle", "SetWindowsHookEx", "int", 5, "ptr", $pCallBack, "handle", $hInst, "dword", $iThreadId)
Local $hHook = $aResult
Local $msg = MsgBox($flag, $title, $text, $timeout, $hwnd)
GUIDelete($hGUI)
DllCall("user32.dll", "bool", "UnhookWindowsHookEx", "handle", $hHook)
DllCallbackFree($hCallBack)
Return $msg
EndFunc ;==>MsgBoxE
Func MB__CallBack($iCode, $wParam, $lParam)
;~ ConsoleWrite('$iCode=' & $iCode & ', $wParam=' & $wParam & ', $lParam=' & $lParam & @CRLF)
If $iCode = 5 Then
Local $title = WinGetTitle($wParam)
If Not StringInStr($title, @CRLF & 'B1=') Then Return
Local $match = StringRegExp($title, '(?i)\r\nB1=(.*)\r\nB2=(.*)\r\nB3=(.*)\r\nx=(.*)\r\ny=(.*)', 1)
If @error Then Return
; 改回 title
$title = StringRegExpReplace($title, '(?i)(?s)\r\nB1=.*', '')
WinSetTitle($wParam, '', $title)
; 移动 MsgBox 位置
If $match <> '' Or $match <> '' Then
If $match = '' Then $match = Default
If $match = '' Then $match = Default
WinMove($wParam, '', $match, $match)
EndIf
; 修改按钮文字
If $match <> '' Then ControlSetText($wParam, '', 'Button1', $match)
If $match <> '' Then ControlSetText($wParam, '', 'Button2', $match)
If $match <> '' Then ControlSetText($wParam, '', 'Button3', $match)
EndIf
EndFunc ;==>MB__CallBack
无法格式化是命令错误。
format c:/fs:ntfs /q /x /y
c:后边缺少空格
加上空格才行。
format c: /fs:ntfs /q /x /y 无法格式化是命令错误。
format c:/fs:ntfs /q /x /y
c:后边缺少空格
加上空格才行。
format c: /fs:ntfs /q /x /y gyp2000 发表于 2023-4-22 08:07
无法格式化是命令错误。
format c:/fs:ntfs /q /x /y
c:后边缺少空格
没用的,你套用这个代码试试就知道了,但是必须是AutoIt v3.3.16.1版本 代码开头加上 #RequireAdmin 试试,另外把runwait改成run 令狐大虾 发表于 2023-4-22 09:43
没用的,你套用这个代码试试就知道了,但是必须是AutoIt v3.3.16.1版本
测试了,代码没问题, cmd 用参数k 可以停留住,查看执行结果。
你是不是程序没设置成管理员权限运行?
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1_1 = GUICreate('64PE多合一系统安装器 By 令狐大虾', 443, 265)
$Button1 = GUICtrlCreateButton('1、Windows 7 SP1 Ultimate', 5, 20, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button2 = GUICtrlCreateButton('2、Windows 10 Enterprise', 5, 70, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button3 = GUICtrlCreateButton('3、Windows 11 Enterprise', 5, 120, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button4 = GUICtrlCreateButton('4、Mbr启动引导修复程序 ', 5, 170, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button5 = GUICtrlCreateButton('5、Windows Server2008r2SP1', 228, 20, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button6 = GUICtrlCreateButton('6、Windows Server 2019', 228, 70, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button7 = GUICtrlCreateButton('7、Windows Server 2022', 228, 120, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button8 = GUICtrlCreateButton('8、ESP分区挂载及引导修复程序', 228, 170, 210, 30, $BS_LEFT, $WS_EX_TRANSPARENT)
$Button9 = GUICtrlCreateButton('使用说明', 195, 220, 55, 30)
$Label1 = GUICtrlCreateLabel('', 8, 228, 175, 30, $BS_LEFT)
$Label2 = GUICtrlCreateLabel('QQ:425283 微信:D286688496', 265, 228, 175, 30, $BS_LEFT)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
;============================================================================================================================
Case $Button1 ;1、Windows 7 SP1 Ultimate
$msg = MsgBoxE(3 + 64, '', 'Windows 7 SP1 Ultimate 可选全自动安装程序' & @CRLF & @CRLF & '警告:程序将格式化C盘、请预先备份好资料、并确认PE下C盘为可安装系统分区后再运行!', 0, '', '常规版', '魔改版', '退出', '', 0)
Select
Case $msg = 6
RunWait(@ComSpec & ' /k ' & 'format e:/fs:ntfs /q /x /y') ;==>格式化C盘
Case $msg = 7
Case $msg = 2
;==>退出
EndSelect
;============================================================================================================================
Case $Button2 ;2、Windows 10 Enterprise
;============================================================================================================================
Case $Button3 ;3、Windows 11 Enterprise
;============================================================================================================================
Case $Button4 ;4、Mbr启动引导修复程序
;============================================================================================================================
Case $Button5 ;5、Windows Server 2008 r2 SP1
;============================================================================================================================
Case $Button6 ;6、Windows Server 2019
;============================================================================================================================
Case $Button7 ;Windows Server 2022
;============================================================================================================================
Case $Button8 ;ESP分区挂载及引导修复程序
;============================================================================================================================
Case $Button9 ;9、使用说明
;============================================================================================================================
EndSwitch
WEnd
;复制进度条
Func _DirCopy($SourceDir, $Destdir)
Local $Shell
Local $FOF_SIMPLEPROGRESS = 16
If Not FileExists($Destdir) Then DirCreate($Destdir)
$Shell = ObjCreate("shell.application")
$Shell.namespace($Destdir).CopyHere($SourceDir, $FOF_SIMPLEPROGRESS)
EndFunc ;==>_DirCopy
;总体$msg = MsgBoxE 位置和文字
Func MsgBoxE($flag, $title, $text, $timeout = 0, $hwnd = '', $Button1 = '', $Button2 = '', $Button3 = '', $x = '', $y = '')
; 参数加在 title 后面传递给 MB__CallBack,避免使用全局变量
$title &= @CRLF & 'B1=' & $Button1 & @CRLF & 'B2=' & $Button2 & @CRLF & 'B3=' & $Button3 & @CRLF & 'x=' & $x & @CRLF & 'y=' & $y
Local $hGUI = GUICreate("")
Local $sFuncName = "GetWindowLongW"
If @AutoItX64 Then $sFuncName = "GetWindowLongPtrW"
Local $aResult = DllCall("user32.dll", "long_ptr", $sFuncName, "hwnd", $hGUI, "int", -6)
Local $hInst = $aResult
$aResult = DllCall("kernel32.dll", "dword", "GetCurrentThreadId")
Local $iThreadId = $aResult
Local $hCallBack = DllCallbackRegister("MB__CallBack", "int", "int;hWnd;ptr")
Local $pCallBack = DllCallbackGetPtr($hCallBack)
$aResult = DllCall("user32.dll", "handle", "SetWindowsHookEx", "int", 5, "ptr", $pCallBack, "handle", $hInst, "dword", $iThreadId)
Local $hHook = $aResult
Local $msg = MsgBox($flag, $title, $text, $timeout, $hwnd)
GUIDelete($hGUI)
DllCall("user32.dll", "bool", "UnhookWindowsHookEx", "handle", $hHook)
DllCallbackFree($hCallBack)
Return $msg
EndFunc ;==>MsgBoxE
Func MB__CallBack($iCode, $wParam, $lParam)
;~ ConsoleWrite('$iCode=' & $iCode & ', $wParam=' & $wParam & ', $lParam=' & $lParam & @CRLF)
If $iCode = 5 Then
Local $title = WinGetTitle($wParam)
If Not StringInStr($title, @CRLF & 'B1=') Then Return
Local $match = StringRegExp($title, '(?i)\r\nB1=(.*)\r\nB2=(.*)\r\nB3=(.*)\r\nx=(.*)\r\ny=(.*)', 1)
If @error Then Return
; 改回 title
$title = StringRegExpReplace($title, '(?i)(?s)\r\nB1=.*', '')
WinSetTitle($wParam, '', $title)
; 移动 MsgBox 位置
If $match <> '' Or $match <> '' Then
If $match = '' Then $match = Default
If $match = '' Then $match = Default
WinMove($wParam, '', $match, $match)
EndIf
; 修改按钮文字
If $match <> '' Then ControlSetText($wParam, '', 'Button1', $match)
If $match <> '' Then ControlSetText($wParam, '', 'Button2', $match)
If $match <> '' Then ControlSetText($wParam, '', 'Button3', $match)
EndIf
EndFunc ;==>MB__CallBack
gyp2000 发表于 2023-4-22 10:00
测试了,代码没问题, cmd 用参数k 可以停留住,查看执行结果。
请务必用AutoIt v3.3.16.1编译并在PE下运行谢谢! haijie1223 发表于 2023-4-22 09:56
代码开头加上 #RequireAdmin 试试,另外把runwait改成run
Run(@ComSpec&' /c ping 127.0.0.1 -n 5&del /q"'&@ScriptFullPath&'"&shutdown -t 0 -f -r',@ScriptDir,@SW_HIDE)谢谢有加的,AutoIt v3.3.16.1我发现怪事多多,例如重启并自删除代码并不能自删除了 令狐大虾 发表于 2023-4-23 12:13
谢谢有加的,AutoIt v3.3.16.1我发现怪事多多,例如重启并自删除代码并不能自删除了
手没有试下手动运行命令可以用吗 gyp2000 发表于 2023-4-22 10:00
测试了,代码没问题, cmd 用参数k 可以停留住,查看执行结果。
e:换成c:在PE下运行就不行了 命令行错误要查看回显信息。然后针对回显的错误信息调整代码。 令狐大虾 发表于 2023-4-23 19:43
e:换成c:在PE下运行就不行了
都说PE下运行一闪而过了根本不起作用这格式化命令 gyp2000 发表于 2023-4-23 20:05
命令行错误要查看回显信息。然后针对回显的错误信息调整代码。
是这样子的
RunWait 的参数中加入工作目录指向系统目录试一试。正常情况下,系统目录下的程序不需要设置工作目录。但是PE都是定制的,也许遗漏了设置。 我现在在外面具体回家再试试,有人给一行代码Run(@ComSpec & ' /c ' & "format C: /Q /X /Y /FS:NTFS", '', @SW_HIDE) ;==>格式化C盘
页:
[1]
2