找回密码
 加入
搜索
查看: 6496|回复: 17

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

[复制链接]
发表于 2020-6-11 16:44:23 | 显示全部楼层 |阅读模式
本帖最后由 lizhongbo 于 2020-6-11 16:52 编辑

比如系统盘符是,c,d,e,f,g,y,z      我需要的就是hijklmnopqrstuvwx
希望高手帮帮忙



#include <WinAPIFiles.au3>
#include <Array.au3>
#include <AutoItConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 330, 86)
$Combo1 = GUICtrlCreateCombo("", 80, 24, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))


Opt('MustDeclareVars', 1)
Global $aDisk,$nMsg,$k
Global $iDriveIndex = 0, $aDiskList[1] ;用来保存磁盘序号
Global $sPartion = '', $aDriveNumber
Global $aFixedDrive, $aCdDrive, $aRemovableDrive
Global $aNewOrder, $aNewOrderInfo[1][3], $aFixedOrder[27]

GUISetState(@SW_SHOW)
$k = ("a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:v:w:y:z:")
;SplashTextOn('', "正在理顺系统盘符", 350, 40, @DesktopWidth / 2 - 350 / 2, @DesktopHeight / 2 - 40 / 2, 1)
;Sleep(500)
;SplashOff()
While 1
        $aDisk = _WinAPI_GetDriveGeometryEx($iDriveIndex)
        If @error Then ExitLoop
        ReDim $aDiskList[UBound($aDiskList) + 1]
        $aDiskList[UBound($aDiskList) - 1] = $iDriveIndex
        $aDiskList[0] = UBound($aDiskList) - 1
        $iDriveIndex += 1
WEnd

$aFixedDrive = DriveGetDrive('Fixed')
If IsArray($aFixedDrive) Then
        For $j = 1 To $aDiskList[0]
                For $i = 1 To $aFixedDrive[0]
                        $aDriveNumber = _WinAPI_GetDriveNumber($aFixedDrive[$i])

                        If IsArray($aDriveNumber) Then

                                If $aDriveNumber[1] = $aDiskList[$j] Then $aFixedOrder[$aDriveNumber[2]] = StringUpper($aFixedDrive[$i])
                                ;GUICtrlSetData($Combo1, StringUpper($aFixedDrive[$i]),StringUpper($aFixedDrive[0]))
                                ;MsgBox(4096,"", "找到" &StringUpper($aFixedDrive[$i]) & "盘符")
                        EndIf
                Next
                $sPartion &= _ArrayToString($aFixedOrder, '')
                For $i = 1 To 26
                        $aFixedOrder[$i] = ''
                        ;MsgBox(4096,"", "找到" &$aFixedOrder[$i] & "盘符")
                Next
        Next
EndIf
$aCdDrive = DriveGetDrive('CDROM')
If IsArray($aCdDrive) Then
        For $i = 1 To $aCdDrive[0]
                If Not StringInStr('a:b:x:y:z:', $aCdDrive[0]) Then $sPartion &= StringUpper($aCdDrive[$i])
                MsgBox(4096,"", "找到" & $aCdDrive[$i] & "盘符")
        Next
EndIf
$aRemovableDrive = DriveGetDrive('REMOVABLE')
If IsArray($aRemovableDrive) Then
        For $i = 1 To $aRemovableDrive[0]
                If Not StringInStr('a:b:x:y:z:', $aRemovableDrive[0]) Then $sPartion &= StringUpper($aRemovableDrive[$i])
                ;MsgBox(4096,"", "找到" & $aRemovableDrive[$i] & "盘符")
                ;GUICtrlSetData($Combo1, StringUpper($aRemovableDrive[$i]),StringUpper($aRemovableDrive[$i]))
        Next
EndIf

If Not StringInStr($sPartion, ':') Then
        SplashTextOn('', "未发现本地磁盘,程序退出", 350, 40, @DesktopWidth / 2 - 350 / 2, @DesktopHeight / 2 - 40 / 2, 1)
        Sleep(1000)
        Exit
Else
For $i = 1 To 26 Step 1
If Not StringInStr($k, $sPartion[$i]) Then GUICtrlSetData($Combo1, $sPartion[$i],$sPartion[$i])


        Next
EndIf








While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd

















 楼主| 发表于 2020-6-11 17:03:59 | 显示全部楼层

谢谢,我试一下!
 楼主| 发表于 2020-6-11 17:11:57 | 显示全部楼层

不错是这样的,可是怎么分割插入,下拉列表框里呢?
发表于 2020-6-11 18:33:31 | 显示全部楼层
怎么搞这么复杂……
GUICreate('可用盘符', 330, 86)
$Combo1 = GUICtrlCreateCombo('', 80, 24, 145, 25)
For $ii = 67 To 90
        If Not FileExists(Chr($ii) & ':') Then GUICtrlSetData(-1, Chr($ii) & ':')
Next
GUISetState()
While GUIGetMsg() <> -3
WEnd
 楼主| 发表于 2020-6-11 18:44:54 | 显示全部楼层
afan 发表于 2020-6-11 18:33
怎么搞这么复杂……

还是a版厉害,几句代码就搞定了,但如何排除y和Z呢?
发表于 2020-6-11 18:46:41 | 显示全部楼层
lizhongbo 发表于 2020-6-11 18:44
还是a版厉害,几句代码就搞定了,但如何排除y和Z呢?

For $ii = 67 To 88
 楼主| 发表于 2020-6-11 18:49:19 | 显示全部楼层

谢谢,太感谢了
 楼主| 发表于 2020-6-11 19:39:52 | 显示全部楼层
afan 发表于 2020-6-11 18:33
怎么搞这么复杂……

问题又来了a版,怎么让下拉列表框选中第一项内容呢?
发表于 2020-6-11 19:50:14 | 显示全部楼层
lizhongbo 发表于 2020-6-11 19:39
问题又来了a版,怎么让下拉列表框选中第一项内容呢?

方法有多种,这里仅举一例,在我上面的示例代码第6行(GUISetState())下面加上
ControlCommand('', '', $Combo1, 'SetCurrentSelection', 0)
即可
 楼主| 发表于 2020-6-11 19:56:05 | 显示全部楼层
把862228699的和a版的结合了一下,达到了需要的效果,只是不能选中列表框的第一项

GUICreate('可用盘符', 330, 86)
$Combo1 = GUICtrlCreateCombo('', 80, 24, 145, 25)

For $i = 67 To 90
        If Not FileExists(Chr($i) & ':') Then


If StringRegExp('X', '(?i)' & Chr($i)) = 0 Then GUICtrlSetData($Combo1, Chr($i), Chr($i))

EndIf
Next




GUISetState()
While GUIGetMsg() <> -3
WEnd

 楼主| 发表于 2020-6-11 20:03:30 | 显示全部楼层
afan 发表于 2020-6-11 19:50
方法有多种,这里仅举一例,在我上面的示例代码第6行(GUISetState())下面加上
ControlCommand('', '', $ ...

不胜感谢a版
发表于 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

您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-23 08:15 , Processed in 0.073943 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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