NSIS: Getting an unused drive letter
NSIS November 26th, 2007You'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
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
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.
That's it.
More info at http://nsis.sourceforge.net/GetDrives
Recent Comments