Archive: detecting a logical drive


detecting a logical drive
I can use FindFirst or IfFileExists with an argument of "D:\*.*" and find if there is something in the D:\ drive. What about if D:\ exists, but is empty? How can I detect it?

mdm


You can use:

System::Call "kernel32::GetDriveTypeA(t 'D:\') i .s"
Pop $0
StrCmp $0 0 doesntExist
StrCmp $0 1 doesntExist
# exists code here
doesntExist:
# doesn't exist code here


Thanks,
mdm


hi!
but what about detecting all logical drivers(HD's)?
I would need something, that would detect, if computer has more than one logical driver, and if it has more, then put all avaliable drivers to variables.
And if it is possible, what i asked, then maybe this scipt could put driver of default program files($PROGRAMFILES) to sertain variable.

i really hope, that it is possible..tnx


That is possible. Check MSDN for the GetDriveType return values.


ok, but i'm really not familiar to MSDN...haven't used it :S
could you please help me with a part of nsi script?


These are the return values from the MSDN page on "Using the GetDriveType Function" (http://msdn.microsoft.com/archive/de...dn_msdn165.asp)

Value / Drive Type
0 - Unknown media type
1 - No such root directory exists
DRIVE_REMOVABLE - Drive can be removed
DRIVE_FIXED - Drive cannot be removed
DRIVE_REMOTE - Network disk drive
DRIVE_CDROM - CD-ROM disk drive
DRIVE_RAMDISK - RAM disk drive

-Stu


DRIVE_CDROM = 5
DRIVE_FIXED = 3
DRIVE_RAMDISK = 6
DRIVE_REMOTE = 4
DRIVE_REMOVABLE = 2


There is already a function on the Archive that does this for you, no need to reinvent the wheel:

http://nsis.sourceforge.net/archive/...php?pageid=277


no need to reinvent the wheel
Hehe.

Maybe I didn't add the DRIVE_RAMDISK = 6, DRIVE_REMOTE = 4. I didn't know they are from... If "More is better" I will add those at once today or tomorrow.

hi..sry, but i expressed myself wrongly :$ what i really needed as a result was a names or letters of hard drives. for example, i have in my pc sutch driver letters:
A:\ - Floppy ; C:\ - HD ; D:\ - HD ; E:\ - HD ; F:\ - CD-R ; G:\ - CD-WR
(c:\ and d:\ are partitions of one hard driver). The results what i would need script to give are:
$R1 - a:\
$R2 - c:\
$R3 - d:\
$R4 - e:\
$R5 - f:\
$R6 - g:\
or if it is possible, then only letters of hard drivers (c:\ ; d:\ ; e:\ )
so, is this possible? tnx


In the callback function:

You can use any variables, but the $R0 have a function result, the drive letter detected.
But to do this below, you have to include your code in this callback function, because the number of variables can vary, so:

Function Callback

# In your code, the variable $R0 will be the hard drive letter
# detected

# Push "go" if want to go
# Push "stop" to stop

FunctionEnd
The code will be executed EVERYTIME that detects a hard drive.