Retrieve Disk Capacity: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library)
 
No edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{PageAuthor|dirtydingus}}
== Description ==
== Description ==
'''Note:''' GetDiskFreeSpaceEx is not supported by the first edition of Windows 95.
'''Note:''' GetDiskFreeSpaceEx is not supported by the first edition of Windows 95.
Line 10: Line 12:


== Notes ==
== Notes ==
I suspect there may be problems if the drive size is >2Tb as then it will no longer be a 32bit integer.
I suspect there may be problems if the drive size is >2Tb as then it will no longer be a 32bit integer. (Adam: this doesn't seem right to me, though I'm not sure.  2^32 is about 4 GB's and I'm easily able to represent that large of a number returned from this.  But if registers can hold > 32 bits then I don't know why there's System::Int64Op?)


Also on volumes with user quotas (ie NTFS servers) the amount may be less tham the actual amount - this warning is courtesy of the Microsoft documentation on the [http://msdn.microsoft.com/library/en-us/fileio/base/getdiskfreespaceex.asp GetDiskFreeSpaceEx] function.
Also on volumes with user quotas (ie NTFS servers) the amount may be less tham the actual amount - this warning is courtesy of the Microsoft documentation on the [http://msdn.microsoft.com/library/en-us/fileio/base/getdiskfreespaceex.asp GetDiskFreeSpaceEx] function.
Please note that the function returns the capacity of the volume that the specified directory is in. See the more detailed note at [[CheckSpaceFree]].


== The Script ==
== The Script ==
Line 32: Line 36:
</highlight-nsis>Share & Enjoy
</highlight-nsis>Share & Enjoy


Page author: dirtydingus
[[Category:Disk, Path & File Functions]]

Latest revision as of 02:18, 10 April 2011

Author: dirtydingus (talk, contrib)


Description

Note: GetDiskFreeSpaceEx is not supported by the first edition of Windows 95.

Use GetDiskFreeSpace instead if you want your check to be compatible with this version.


This code is based on Sunjammer's code to CheckSpaceFree, but uses the same system function call to return the drive capacity instead.

The value returned is the amount in KBytes.

Notes

I suspect there may be problems if the drive size is >2Tb as then it will no longer be a 32bit integer. (Adam: this doesn't seem right to me, though I'm not sure. 2^32 is about 4 GB's and I'm easily able to represent that large of a number returned from this. But if registers can hold > 32 bits then I don't know why there's System::Int64Op?)

Also on volumes with user quotas (ie NTFS servers) the amount may be less tham the actual amount - this warning is courtesy of the Microsoft documentation on the GetDiskFreeSpaceEx function.

Please note that the function returns the capacity of the volume that the specified directory is in. See the more detailed note at CheckSpaceFree.

The Script

!define sysGetDiskFreeSpaceEx 'kernel32::GetDiskFreeSpaceExA(t, *l, *l, *l) i'
 
; $1 - path to check (e.g. 'C:\') should work on \\computer\share\ also
; $1 - trashed returns vol space in KBytes 
; (NB odd things may happen on >2Tb drives, have not checked)
function GetCapacityFunc
  push $2
  System::Call '${sysGetDiskFreeSpaceEx}(r1,.,.r2,)'
  ; convert the large integer byte values into managable kb
  System::Int64Op $2 / 1024
  Pop $1
  Pop $2
functionend

Share & Enjoy