Skip to content
⌘ NSIS Forum Archive

How to detect flash drive

9 posts

C_10#

How to detect flash drive

Hi,

I want to detect a USB flash drive once the user connect it.
It should look like this:
; Disable next button while USB flash drive not identified
GetDlgItem $0 $HWNDPARENT 1 ; next=1, cancel=2, back=3
EnableWindow $0 0
loop:
${If}
# usb is detected
${Else}
Goto loop
${EndIf}
; Enable next button
GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 1
I hope you have some ideas,
Thanks!
C_10#
Now first of all my custom function search the flash drive and then I can see text/label/image and so on...
But i want it the other way round...

How can I do this?

Function customFunction
nsDialogs::Create 1018
; Text, label, image
...
; Disable next button while USB flash drive not identified
GetDlgItem $0 $HWNDPARENT 1 ; next=1, cancel=2, back=3
EnableWindow $0 0
; Search flash drive
...
; Enable next button
GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 1
nsDialogs::Show
${NSD_FreeImage} $Image
FunctionEnd
Thanks
C_10#
Hmm, perhaps I should attach some images.

While searching the flash drive I can't see the images/labels (see attachments).
But I want that you can see the page with all components first, and after that the installer should search the flash drive.

I hope you understand what I mean, please help
MSG#
Once you do nsDialogs::Show, the installer will wait until the Next button is pressed (or any other button which has a callback function defined). The installer cannot wait for two things at the same time (Next button and flash drive). So you'll need to do the flashdrive search in the page's leave function. The page would then say "please insert the flash drive and click Next to continue". If in the leave function no drive is found, call abort and the installer will stay on the 'please insert' page.
C_10#
Thanks MSG! That's a good idea, but I've one problem:

So you'll need to do the flashdrive search in the page's leave function
I've a custom page, so I can't use "!define MUI_PAGE_CUSTOMFUNCTION_LEAVE"
Can I copy the flashdrive search after
nsDialogs::Show
${NSD_FreeImage} $Image
and make so my own customFunction leave?

Function customFunction
nsDialogs::Create 1018
; Text, label, image
...
nsDialogs::Show
${NSD_FreeImage} $Image

; search flash drive
...
MessageBox MB_YESNO "Leave Function TEST! Go to next page?" IDYES +2
Abort

FunctionEnd
I can see the MessageBox, but when I click on "No", I'm on the next page anyway...
MSG#
Page custom customFunction customLeaveFunction