Reputation: 155
I would like the Inno Setup compiler to automatically detect USB drive letter and use it a source path for installer files.
But I dont know exactly how to identify the right drive. What is the right SourceDir=
for that?
The source drive should not be a fix drive.
Upvotes: 2
Views: 354
Reputation: 202197
Inno Setup cannot do this on its own. But you can invoke a simple PowerShell code from Inno Setup preprocessor.
Based on Get the drive letter of USB drive in PowerShell, the following will set SourceDir
to first removable drive (not necessarily the USB drive, and it won't use USB hard drives). If you really want the first USB drive, try the answer by @CB.
#define GetUsbDrive() \
Local[0] = AddBackslash(GetEnv("TEMP")) + "usb_drive.txt", \
Local[1] = \
"-ExecutionPolicy Unrestricted -Command """ + \
"$drive = @(Get-WmiObject Win32_Volume -Filter DriveType='2'); " + \
"if ($drive) { $drive = $drive[0].DriveLetter }; " + \
"Set-Content -Path '" + Local[0] + "' -NoNewline -Value $drive " + \
"""", \
Exec("powershell.exe", Local[1], SourcePath, , SW_HIDE), \
Local[2] = FileOpen(Local[0]), \
Local[3] = FileRead(Local[2]), \
FileClose(Local[2]), \
DeleteFileNow(Local[0]), \
Local[3]
#define UsbDrive GetUsbDrive()
#if Len(UsbDrive) == 0
#error No USB drive found
#endif
[Setup]
SourceDir={#UsbDrive}
Upvotes: 1