GetDiskSpace Example
InstallShield 2024 » InstallScript Language Reference
Note:To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.
/*--------------------------------------------------------------*\
*
* InstallShield Example Script
*
* Demonstrates the GetDiskSpace function.
*
* This script gets a fully qualified path from the end user.
* It then extracts the drive designation from the path, gets
* the amount of free space on that drive, and displays the
* amount of free space in a message box.
*
* A script-defined function is used to insert commas if
* necessary into the number before it's displayed.
*
\*--------------------------------------------------------------*/
// User-defined function to format a number in a string.
prototype FormatIntString (BYREF STRING);
// Include Ifx.h for built-in InstallScript function prototypes.
#include "Ifx.h"
export prototype ExFn_GetDiskSpace(HWND);
function ExFn_GetDiskSpace(hMSI)
STRING svResultPath, svDrive;
LONG lFreeSpace;
STRING svFreeSpace;
begin
// Prompt for a target path; use C as the default.
AskPath ("Select drive:", "C:\\", svResultPath);
// Get the drive designation from the path.
GetDisk (svResultPath, svDrive);
// Get the amount of free disk space on that drive.
lFreeSpace = GetDiskSpace (svDrive);
if (lFreeSpace < 0) then
// Handle an error from GetDiskSpace.
MessageBox ("GetDiskSpace failed.", SEVERE);
else
// Convert the free disk space value to a string.
NumToStr (svFreeSpace, lFreeSpace);
// Insert commas into the number if necessary.
FormatIntString (svFreeSpace) ;
// Report the amount of free space.
MessageBox (svFreeSpace + " bytes free on drive " + svDrive + ".",
INFORMATION);
endif;
end;
function FormatIntString(svInteger)
// Insert commas if necessary into an integer
// that's been stored in a string variable.
INT nLen;
STRING svSubStr, svTemp;
begin
nLen = StrLength (svInteger);
if nLen > 3 then
nLen = nLen - 3;
StrSub (svTemp , svInteger, nLen, 3);
while nLen > 3
nLen = nLen - 3;
StrSub (svSubStr, svInteger, nLen, 3);
svTemp = svSubStr + "," + svTemp;
endwhile;
StrSub (svSubStr, svInteger, 0,nLen);
svInteger = svSubStr + "," + svTemp;
endif;
end;