找回密码
 加入
搜索
楼主: lizhongbo

[AU3基础] 通过对比,获取系统未使用的盘符的方法求助

[复制链接]
发表于 2020-6-11 20:04:01 | 显示全部楼层
瞎扯一下,嘿嘿!

Global $pf = 0
GUICreate('可用盘符', 330, 86)
$Combo1 = GUICtrlCreateCombo('', 80, 24, 145, 25)
For $ii = 67 To 88
        If $pf = 0 And Not FileExists(Chr($ii) & ':') Then $pf = $ii
        If Not FileExists(Chr($ii) & ':') Then GUICtrlSetData(-1, Chr($ii) & ':', Chr($pf) & ':')
Next
GUISetState()
While GUIGetMsg() <> -3
WEnd
发表于 2020-6-11 20:10:46 | 显示全部楼层
A版方法简单暴力,学习一下
 楼主| 发表于 2020-6-11 22:05:45 | 显示全部楼层
本帖最后由 lizhongbo 于 2020-6-12 10:05 编辑
xzf680 发表于 2020-6-11 20:04
瞎扯一下,嘿嘿!
[au3]
Global $pf = 0

谢谢,还有个问题就是,添加一个按钮,每点击一次按钮,组合框内容就显示下一项内容!这个搞定了,但是如果卸载,组合框当前项,向上选中一项,不知道怎么弄了!!!源码如下


#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <GuiComboBoxEx.au3>
#include <GuiComboBox.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("可用盘符", 306, 96)
$Combo1 = GUICtrlCreateCombo("", 24, 16, 145, 25)
$Button1 = GUICtrlCreateButton("确认挂载", 200, 16, 75, 25)
$Button2 = GUICtrlCreateButton("卸载", 200, 56, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $pf = 0
Global $aNewOrder, $aNewOrderInfo[1][3], $aFixedOrder[27]


For $i = 65 To 90
        If $pf = 0 And Not FileExists(Chr($i) & ':') Then $pf = $i
        If Not FileExists(Chr($i) & ':') Then
                If StringRegExp('XY', '(?i)' & Chr($i)) = 0 Then GUICtrlSetData($Combo1, Chr($i), Chr($pf))
                EndIf
Next



Func zhkxyg($up="")
$sPartion=_GUICtrlComboBox_GetList ( $Combo1 )

If StringRight($sPartion, 1) == '|' Then $sPartion = StringTrimRight($sPartion, 1)
$aNewOrder = StringSplit($sPartion, '|', 1)
ReDim $aNewOrderInfo[UBound($aNewOrder)][3]
$aNewOrderInfo[0][0] = $aNewOrder[0]



For $i = 1 To $aNewOrder[0]
_GUICtrlComboBoxEx_SetCurSel($Combo1,GUICtrlRead($Combo1))

If GUICtrlRead($Combo1)=$aNewOrder[$i] Then
;MsgBox(4096,"", "找到1" &$aNewOrder[$i])
If $up ="" Then ControlCommand('', '', $Combo1, 'SetCurrentSelection',$i)
;If $up <>"" Then ControlCommand('', '', $Combo1, 'SetCurrentSelection',$i-1)
ExitLoop
EndIf
If GUICtrlRead($Combo1)<>$aNewOrder[$i] And $up <>"" Then
If $up <>"" Then ControlCommand('', '', $Combo1, 'SetCurrentSelection',$i)
ExitLoop
EndIf


Next
EndFunc




While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $Button1
zhkxyg()
                Case $Button2
zhkxyg("1")
;MsgBox(4096,"", "找到" & _GUICtrlComboBox_GetList ( $Combo1 ))


;_GUICtrlComboBoxEx_SetCurSel($Combo1,GUICtrlRead($Combo1)+1)
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd




发表于 2020-6-12 16:09:08 | 显示全部楼层

N年前的作品,给你参考一下:

NT5 系统安装程序及源码
#include <GUIConstantsEx.au3>

GUICreate("系统安装",185,145)

Dim $ISO
$ISO = FileFindFirstFile("*.IS?")  
If $ISO = -1 Then
    MsgBox(0,"错误","没有发现系统镜像文件!")
    Exit
EndIf
If Not FileExists("ISOCmd.exe") And Not FileExists("ISODrive.sys") Then
        MsgBox(0,"错误","没有发现虚拟光驱程序!")
        Exit
Else
        RunWait("ISOCmd.exe -r","",@SW_HIDE)
EndIf

Dim $FF,$FS[32],$NF
$FF = FileFindNextFile($ISO)
For $i = 1 to 31 Step 1
        $FS[$i] = FileFindNextFile($ISO)
    If @error Then
                ExitLoop
        Else
                $FS[0] = $i
        EndIf
Next
FileClose($ISO)
For $i = 1 To $FS[0] Step 1
        $NF = $NF & $FS[$i]
        If $i <> $FS[0] Then $NF = $NF & "|"
Next

GUICtrlCreateLabel("系统镜像:",15,15)
$ComboList_1 = GUICtrlCreateCombo($FF,75,12,98)
If $FS[0] > 0 Then GUICtrlSetData(-1,$NF)
$Combo1 = GUICtrlRead($ComboList_1)

$DriveList = DriveGetDrive("FIXED")
If @error Then Exit
Dim $List
For $i=2 To $DriveList[0] Step 1
        $List = $List & StringUpper($DriveList[$i])
        If $i <> $DriveList[0] Then $List = $List & "|"
Next

GUICtrlCreateLabel("虚拟光驱:",15,40)
Dim $all,$j,$k,$l,$v
$all = DriveGetDrive("all")
If Not @error Then
    For $i = 1 To $all[0]
        $j = $j & $all[$i]
    Next
EndIf
For $i = 122 To 99 Step -1
        If Not StringInStr($j,Chr($i)) Then $k = $k & Chr($i-32) & ":|"
Next
$l = StringSplit($k,"|")
For $i = 2 To $l[0] Step 1
        $v = $v & $l[$i]
        If $i < $l[0]-1 Then $v = $v & "|"
Next
$ComboList_2 = GUICtrlCreateCombo($l[1],75,37,38)
GUICtrlSetData(-1,$v,$l[0])
$Combo2 = GUICtrlRead($ComboList_2)

$Checkbox_1 = GUICtrlCreateCheckbox("IAR",120,37,55,20)

GUICtrlCreateLabel("启动分区:",15,65)
$ComboList_3 = GUICtrlCreateCombo(StringUpper($DriveList[1]),75,62,38)
GUICtrlSetData(-1,$List,$DriveList[1])
$Combo3 = GUICtrlRead($ComboList_3)

$Checkbox_2 = GUICtrlCreateCheckbox("重 启",120,62,55,20)

GUICtrlCreateLabel("安装分区:",15,90)
$ComboList_4 = GUICtrlCreateCombo(StringUpper($DriveList[1]),75,87,38)
GUICtrlSetData(-1,$List,$DriveList[1])
$Combo4 = GUICtrlRead($ComboList_4)

$Checkbox_3 = GUICtrlCreateCheckbox("格式化",120,87,55,20)

$Checkbox_4 = GUICtrlCreateCheckbox("运行安装程序",15,115,88,20)

$Button = GUICtrlCreateButton("开始",120,113,55)

GUICtrlSetState($Checkbox_1,$GUI_DISABLE)
GUICtrlSetState($Checkbox_2,$GUI_DISABLE)
GUICtrlSetState($Checkbox_3,1)
GUICtrlSetState($Checkbox_4,1)
GUICtrlSetState($Button,$GUI_FOCUS)
GUISetState()

While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        $Combo1 = GUICtrlRead($ComboList_1)
        $Combo2 = GUICtrlRead($ComboList_2)
        $Combo3 = GUICtrlRead($ComboList_3)
        $Combo4 = GUICtrlRead($ComboList_4)
        $Check1 = GUICtrlRead($Checkbox_1)
        $Check2 = GUICtrlRead($Checkbox_2)
        $Check3 = GUICtrlRead($Checkbox_3)
        $Check4 = GUICtrlRead($Checkbox_4)
        If $Check2 = 1 Then GUICtrlSetState($Checkbox_4,1)
        $drive = Asc($Combo3)-Asc("A:")
        If $msg = $Button Then
                GUICtrlSetState($Button,$GUI_DISABLE)
                If $Check3 = 1 Then DllCall("shell32.dll","uint","SHFormatDrive","hwnd",0,"uint",$drive,"uint",65535,"uint",1)
                RunWait("ISOCmd.exe -i","",@SW_HIDE)
                RunWait("ISOCmd.exe -n 1","",@SW_HIDE)
                RunWait("ISOCmd.exe -c 1 " & $Combo2,"",@SW_HIDE)
                RunWait(Chr(34) & "ISOCmd.exe" & Chr(34) & " -m " & $Combo2 & " " & Chr(34) & @ScriptDir & "" & $Combo1 & Chr(34),"",@SW_HIDE)
                For $i = 1 To 10
                        If FileExists($Combo2 & "\I386\WINNT32.EXE") Then
                                ExitLoop
                        Else
                                If $i = 10 Then
                                        MsgBox("","退出","没有发现系统的安装文件!")
                                        Exit
                                EndIf
                        EndIf
                        Sleep(1000)
                Next
                $norb = ""
                If $Check2 = 4 Then $norb = " /noreboot"
                If $Check4 = 1 Then Run($Combo2 & "\I386\WINNT32.EXE /s:" & $Combo2 & "\I386 /makelocalsource /syspart:" & $Combo3 & " /tempdrive:" & $Combo4 & " /unattend:" & $Combo2 & "\I386\WINNT.SIF /copysource:lang" & $norb)
                If FileExists($Combo2 & "\OEM") Then DirCopy($Combo2 & "\OEM",$Combo4 & "\OEM",1)
                Exit
        EndIf
WEnd

发表于 2020-6-12 16:32:34 | 显示全部楼层
lizhongbo 发表于 2020-6-11 22:05
谢谢,还有个问题就是,添加一个按钮,每点击一次按钮,组合框内容就显示下一项内容!这个搞定了,但是如 ...

我再瞎扯一下!



#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <GuiComboBoxEx.au3>
#include <GuiComboBox.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("可用盘符", 306, 96)
$Combo1 = GUICtrlCreateCombo("", 24, 16, 145, 25)
$Button1 = GUICtrlCreateButton("确认挂载", 200, 16, 75, 25)
$Button2 = GUICtrlCreateButton("卸载", 200, 56, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $pf = 0
Global $aNewOrder, $aNewOrderInfo[1][3], $aFixedOrder[27]


For $i = 65 To 90
        If $pf = 0 And Not FileExists(Chr($i) & ':') Then $pf = $i
        If Not FileExists(Chr($i) & ':') Then
                If StringRegExp('XY', '(?i)' & Chr($i)) = 0 Then GUICtrlSetData($Combo1, Chr($i), Chr($pf))
        EndIf
Next

Func zhkxyg($up = "")
        $sPartion = _GUICtrlComboBox_GetList($Combo1)

        If StringRight($sPartion, 1) == '|' Then $sPartion = StringTrimRight($sPartion, 1)
        $aNewOrder = StringSplit($sPartion, '|', 1)
        ReDim $aNewOrderInfo[UBound($aNewOrder)][3]
        $aNewOrderInfo[0][0] = $aNewOrder[0]
        For $i = 1 To $aNewOrder[0]
                _GUICtrlComboBoxEx_SetCurSel($Combo1, GUICtrlRead($Combo1))
                If GUICtrlRead($Combo1) = $aNewOrder[$i] Then
                        If $up = "" Then 
                                ControlCommand('', '', $Combo1, 'SetCurrentSelection', $i)
                        Else
                                If $i <> 1 Then _GUICtrlComboBox_SetCurSel($Combo1, $i-2)
                        EndIf
                        ExitLoop
                EndIf
        Next
EndFunc   ;==>zhkxyg

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $Button1
                        zhkxyg()
                Case $Button2
                        zhkxyg("1")
                        ;MsgBox(4096,"", "找到" & _GUICtrlComboBox_GetList ( $Combo1 ))
                        ;_GUICtrlComboBoxEx_SetCurSel($Combo1,GUICtrlRead($Combo1)+1)
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
发表于 2020-6-12 16:45:11 | 显示全部楼层
本帖最后由 xzf680 于 2020-6-12 16:48 编辑


#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <GuiComboBoxEx.au3>
#include <GuiComboBox.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("可用盘符", 306, 96)
$Combo1 = GUICtrlCreateCombo("", 24, 16, 145, 25)
$Button1 = GUICtrlCreateButton("确认挂载", 200, 16, 75, 25)
$Button2 = GUICtrlCreateButton("卸载", 200, 56, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $aNewOrder, $aNewOrderInfo[1][3], $aFixedOrder[27]
For $i = 65 To 87
        If Not FileExists(Chr($i) & ':') Then GUICtrlSetData($Combo1, Chr($i))
Next
_GUICtrlComboBox_SetCurSel($Combo1, 0)
Func zhkxyg($up = "")
        $sPartion = _GUICtrlComboBox_GetList($Combo1)
        If StringRight($sPartion, 1) == '|' Then $sPartion = StringTrimRight($sPartion, 1)
        $aNewOrder = StringSplit($sPartion, '|', 1)
        ReDim $aNewOrderInfo[UBound($aNewOrder)][3]
        $aNewOrderInfo[0][0] = $aNewOrder[0]
        For $i = 1 To $aNewOrder[0]
                _GUICtrlComboBoxEx_SetCurSel($Combo1, GUICtrlRead($Combo1))
                If GUICtrlRead($Combo1) = $aNewOrder[$i] Then
                        If $up = "" Then 
                                _GUICtrlComboBox_SetCurSel($Combo1, $i)
                        Else
                                If $i <> 1 Then _GUICtrlComboBox_SetCurSel($Combo1, $i-2)
                        EndIf
                        ExitLoop
                EndIf
        Next
EndFunc   ;==>zhkxyg

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $Button1
                        zhkxyg()
                Case $Button2
                        zhkxyg("1")
                        ;MsgBox(4096,"", "找到" & _GUICtrlComboBox_GetList ( $Combo1 ))
                        ;_GUICtrlComboBoxEx_SetCurSel($Combo1,GUICtrlRead($Combo1)+1)
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
 楼主| 发表于 2020-6-12 17:50:40 | 显示全部楼层
再次表示感谢!!!谢谢大家的帮助
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-3 11:53 , Processed in 0.071697 second(s), 13 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表