Jump to content

DriveGetDrive ComboBox


Recommended Posts

I've got a script that lists all fixed drives by drive letter. It's for a PE project to Import drivers from Host.

Is it possible to add a variable to include drive label.

Also is it possible to move the 1st entry into the blank window.

Any help appreciated.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
$aArray = DriveGetDrive("FIXED")
$sString = _ArrayToString ($aArray, "\Windows|", 1)
$Form1 = GUICreate("Import from Host", 495, 245, 310, 125, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
GUISetBkColor(0x3399FF)
$Label1 = GUICtrlCreateLabel("Select Drive to Import from and click OK", 80, 40, 338, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Combo1 = GUICtrlCreateCombo("", 176, 88, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetData(-1, $sString, "")
$Button1 = GUICtrlCreateButton("OK", 128, 168, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Cancel", 296, 168, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Do

        $msg = GUIGetMsg()
        If $msg = $Button1 Then
        Run("DpinstL.exe /g:" & (GUICtrlRead($Combo1)))
            Exit
        EndIf
        If $msg = $Button2 Then
            Exit
        EndIf

Until $msg = $GUI_EVENT_CLOSE

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd
Edited by trashy
Link to comment
Share on other sites

  • Moderators

Change this line to move the first element of the array into the combo box:

$Combo1 = GUICtrlCreateCombo($aArray[1], 176, 88, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))

Edit: And if you want the Label, you could do this:

$Combo1 = GUICtrlCreateCombo($aArray[1] & ' ' & DriveGetLabel($aArray[1]), 176, 88, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))





Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

trashy,

You can list all of the drives and labels in the combo box but some formatting is required.  Also you have multiple message loops.  I combined your message loops and showed one way to populate a combo box...

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=

$aArray = DriveGetDrive("FIXED")

; format string used to populate combo box
local $comb_str, $ret
for $1 = 1 to $aArray[0]
    $ret = drivegetlabel($aArray[$1])
    if @error then $ret = 'Not Found'
    $comb_str &= $aArray[$1] & ' - ' & $ret & '|'
next

$Form1 = GUICreate("Import from Host", 495, 245, 310, 125, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
GUISetBkColor(0x3399FF)
$Label1 = GUICtrlCreateLabel("Select Drive to Import from and click OK", 80, 40, 338, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Combo1 = GUICtrlCreateCombo('', 128, 88, 245, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

; populate combo box - 3RD parm is default entry (entry shown in edit box)
guictrlsetdata($combo1,$comb_str,stringleft($comb_str,stringinstr($comb_str,'|')-1))

$Button1 = GUICtrlCreateButton("OK", 128, 168, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Cancel", 296, 168, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; combined message loops
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $button2
            Exit
        case $Button1
            Run("DpinstL.exe /g:" & (GUICtrlRead($Combo1)))
    EndSwitch

WEnd

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Thanks kylomas

That's what I wanted listed in combobox, but now NO paramaters being passed to DpinstL.

Need driver letter from $combo1 + Windows

Run("DpinstL.exe /g:" & (GUICtrlRead($Combo1) & "Windows"))

DpinstL.exe /g: = Dpinst GUI  /--   paramaters needed would be C:Windows or D:Windows etc...

I've only been working with AutoIt for a few months and I'm slowly starting to understand.

Very little prior knowledge working with batch and vbscript.

Here's my best working script, would be nice to add drive label but not necessary.

EDIT: Just noticed C: drive listed twice in combobox. Also combined 2 message loops per kylomas advice.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
$aArray = DriveGetDrive("FIXED")
$sString = _ArrayToString ($aArray, "|", 1)
$Form1 = GUICreate("Import from Host", 495, 245, 310, 125, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
GUISetBkColor(0x3399FF)
$Label1 = GUICtrlCreateLabel("Select Drive to Import from and click OK", 80, 40, 338, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Combo1 = GUICtrlCreateCombo($aArray[1], 176, 88, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetData(-1, $sString, "")
$Button1 = GUICtrlCreateButton("OK", 128, 168, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Cancel", 296, 168, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $button2
            Exit
        case $Button1
            Run("DpinstL.exe /g:" & (GUICtrlRead($Combo1) & "\Windows"))
    EndSwitch

WEnd
Edited by trashy
Link to comment
Share on other sites

I was approaching this the wrong way. I'm running Win7PE from a USB hard drive.
What I need is a process that will detect and display needed information about all
attached fixed drives and their installed OS.
Info needed from all attached drives: drive letter and drive label.
Info needed from each attached drives OS: OS version and Arch.
The only parameter needed to pass to other program is drive letter.

I think I've accomplished everything needed except adding OS Version and Arch.
Started another thread dealing with that subject:'?do=embed' frameborder='0' data-embedContent>>
If anyone has the answer please let me know.  Anyway here's my new script,
please look it over for any mistakes or improvements.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>

 gui1()

 Func gui1()
    Global $ip = "localhost"
$objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2")

GUICreate("List Available Drives", 400, 400, -1, -1, $WS_CAPTION)

$colItems = $objWMIService.ExecQuery("SELECT Name, VolumeName FROM Win32_LogicalDisk", "WQL", 0x30)
If IsObj($colItems) Then
    $label = ("")
    For $objItem In $colItems
        $Label = $Label & $objItem.Name & "" & $objItem.VolumeName & @CRLF
    Next
EndIf

GUICtrlCreateLabel($Label, 100, 50)
$Combo1 = GUICtrlCreateCombo("", 100, 250, 200, 20, $CBS_DROPDOWNLIST)
$Button1 = GUICtrlCreateButton("OK", 100, 350, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Cancel", 220, 350, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
For $i = 10 To 99
If drivestatus(chr($i) & ':') = 'READY' Then
If DriveGetType(chr($i) & ":") = 'FIXED' Then guictrlsetdata($Combo1, chr($i) & ':')

EndIf

Next

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Button2
            Exit
        Case $Button1
            Run("DpinstL.exe /g:" & (GUICtrlRead($Combo1) & "\Windows"))
            Exit
    EndSwitch

WEnd

EndFunc   ;==>gui1
Link to comment
Share on other sites

What are you attaching the hard drive to? If it's a computer that is running Windows, you can use FileGetVersion to get the version number of the winver.exe program on the host computer to tell you which version of Windows it's got installed on it. If it's an x64 version it will also have a Program Files (x86) folder on the main drive, if it's an x86 version of windows it won't have that folder. Other than that, I can't think of any easy ways of checking either without using WMI or some other 3rd party software.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Yes, I'm attaching the external Hard drive to a windows computer.

If you're not familiar with Windows PE it's a basic portable OS used for diagnostics, repairs OS install etc...

Windows PE has multiple versions and arch, for each windows version there is a matching PE in x86 and x64 Arch.

The program I'm trying to make is to import drivers from the computers Host OS. Therefore the need to know OS version and arch.

You can't Import x64 drivers to a x86 PE or XP drivers on win7PE. Some people like run multiple  partitions and OS.

My external HD alone has 4 partitions running 4 different PE versions and 1 partition reserved for file storage.

It' easy enough to explore the host computers drive partitions to discover the installed OS version and arch

I'm just trying to automate the process.

Your suggestion has given me some ideas. I'm a noob to autoit so I appreciate any help or advice.

Link to comment
Share on other sites

Following BrewManNH advice I came up with this, but If FileExists returns x86 every time.

EDIT: found my mistake left out a space, now how to add this to my project.

Func Version()
    $version = StringLeft(FileGetVersion("E:Windows\System32\WinVer.exe"), 3)
If StringLeft($version,3) = "6.1" Then
    Return "WIN7"
ElseIf StringLeft($version,3) = "6.0" Then
    Return "VISTA"
ElseIf StringLeft($version,3) = "5.0" Then
    Return "XP"
EndIf
EndFunc   ;==>Version

Func Arch()
    $arch = ("E:\Program Files (x86)")
If FileExists($arch) Then
    Return "x64"
ElseIf Not FileExists($arch) Then
    Return "x86"
EndIf
EndFunc   ;==>Arch


MsgBox(0, "OSVersion",Version() & Arch())

Even if I could make this work how to Incorporate with my project?

I would much rather have OS and Arch showing in Available Drive list than Drive Label.

Edited by trashy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...