Skip to content
⌘ NSIS Forum Archive

About Detect Drives function

7 posts

Dxmega#

About Detect Drives function

I've been looking for a while (3 hours ;~😉 how to implement this function (http://nsis.sourceforge.net/Detect_Drives) in my program.

Im really new to nsis and I can't find any example using that so as my last resort I've posted here.

Whenever I add the function directly to the code, because I dont know any other way, and I call it from the section I have it like this:
Push "All Local Drives" ; Drive types used for the search. See "Drive Types".
Push $0
GetFunctionAddress $0 "CallbackFunction" ; Custom callback function name.
Exch $0
Call DetectDrives
I always get an error on te CallbackFunction.

Processed 1 file, writing output (x86-ansi):
Adding plug-ins initializing function... Done!
Error: resolving install function "CallbackFunction" in install section "" (0)
Note: uninstall functions must begin with "un.", and install functions must not
Error - aborting creation process

I don't know if Im doing anything wrong or its missing anything.

How do I fix this?

Note: Im trying to use this function to get the Driver Letter from a pendrive.

Thanks in advance
-Dxmega
Anders#
Did you delete your stackoverflow question? I was about to ask, do you only care about the volume name?

CallbackFunction is a function you have to implement yourself, it is called once for each drive.
Dxmega#
Yes I did indeed delete the stack over flow question, because I thought I didnt correctly asked it how I should.

Id like to know the name well the letter more exactly like: E:/ or C:/ or D:/.
Anders#
I know you want the drive letter but we need to know what you can use to identify the drive. On Stackoverflow you said something about a name? Kingston? Is that the volume label? Is there anything else you can look for? A file on the thumb drive?

I was going to answer you on Stackoverflow with code checking the volume label but you deleted it too soon.

Edit:

From your deleted question

I wanted to make an installer that would check if a folder existed inside a Usb flash drive.
Do you know the name of a folder that is always present on the drive?

The name of the pen could be a constant, ex: KINGSTON.
Is this the volume label?
Dxmega#
I do know the name of the folder inside of the pendrive. (The folder will never leave the pendrive.)

And

KINGSTON is the name of the pendrive aka Volume Label.
Anders#
Something like this perhaps:

!include LogicLib.nsh
Section
StrCpy $9 "" ; Drive not found
System::Call 'KERNEL32::GetLogicalDrives()i.r1'
${For} $2 0 25
    IntOp $3 1 << $2
    IntOp $4 $1 & $3
    ${IfThen} $4 = 0 ${|} ${Continue} ${|}
    IntOp $3 65 + $2 ; 'A' + drive id
    IntFmt $3 "%c:\" $3
    System::Call 'KERNEL32::GetVolumeInformation(tr3,t.r4,i${NSIS_MAX_STRLEN},*i,*i,*i,t,i${NSIS_MAX_STRLEN})i.r5'
    DetailPrint Debug:$3=$4
    ${If} $5 <> 0
    ${AndIf} $4 == "KINGSTON"
        DetailPrint "Debug:Found drive $3 with volume name $4"
        ${If} ${FileExists} "$3\MySpecialFolder\*"
            DetailPrint "Debug:Found special folder on $3"
            StrCpy $9 $3
        ${EndIf}
    ${EndIf}
${Next}
${If} $9 != ""
    DetailPrint "My drive=$9"
${EndIf}
SectionEnd 
This does not check the drive type but I don't really think that is important if you are checking two other things.
Dxmega#
Im sorry I couldn't reply sooner, my pendrive stopped working so I couldn't test it.
However this is exactly what I needed!
Thank you 🙂 .