You’ll need nsh.zip and extract it in your plugins directory of NSIS.

A top of your NSIS script put this line of code :
[code]
#Custom Macros
!insertmacro GetDrives
[/code]

Put following function in your code :
[code]
/**
* Each time an existing drive is found (${GetDrives}, this function is called
*/
Function DriveFound
StrCpy $9 $9 1 #Take first character and store it in variable 9
${StrReplace} $7 $9 "" $7 #In the string with all drives we replace the found drive by an empty string
Push $0 #Search for next drive
FunctionEnd
[/code]

Now you can get the first unused drive lettter of the alphabet like this :
[code]
StrCpy $7 "CDEFGHIJKLMNOPQRSTUVWXYZ"
${GetDrives} "ALL" "DriveFound" #Search for all existing Drives
StrCpy $7 $7 1 #Take first of free drive-letters.
[/code]

That’s it.

More info at http://nsis.sourceforge.net/GetDrives

pixel NSIS: Getting an unused drive letter
No TweetBacks yet. (Be the first to Tweet this post)