李晓亮的博客

导航

【转】在InstallShield中获取硬盘序列号(英文)

CODE: Getting the Volume Serial Number

Document ID: Q108728
This article applies to the following:
Product(s): InstallShield Professional 6.x, 7.x , InstallShield Developer - All Versions, InstallShield DevStudio 9.x, InstallShield AdminStudio - All Versions
Last Revised On: 10/30/2003

 

Summary

This article provides InstallScript code that will get the volume serial number of the hard drive using the Windows API GetVolumeInformation( ).


 

Discussion

//Before using the GetVolumeInformation API you will need to prototype it
prototype KERNEL32.GetVolumeInformation(BYREF STRING, BYREF STRING, NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF STRING, NUMBER);

//prototype for the custom InstallScript function
prototype GetVolumeSerial();

//function definition
function GetVolumeSerial()
STRING lpRootPathName;
STRING lpVolumeNameBuffer;
NUMBER nVolumeNameSize;
NUMBER lpVolumeSerialNumber;
NUMBER lpMaximumComponentLength;
NUMBER lpFileSystemFlags;
STRING lpFileSystemNameBuffer;
NUMBER nFileSystemNameSize;
BOOL APIReturn;

begin
  lpRootPathName="C:\\";
  nVolumeNameSize=60;
  nFileSystemNameSize=60;
  APIReturn=GetVolumeInformation(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize,   lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize);
  if (APIReturn) then
    SprintfBox(INFORMATION, "", "Volume= %s\nVolume Serial= %d", lpRootPathName, lpVolumeSerialNumber);
  else
    MessageBox("Failure.",0);
  endif;
end

 

Additional Information

Make sure the value stored in the lpRootPathName variable has a trailing backslash. Also, the serial number that is returned by the variable lpVolumeSerialNumber will be in decimal form, not the typical hex form that is displayed by the DOS command volume.


 

References

For more information on the Windows API GetVolumeInformation( ), see the MSDN document GetVolumeInformation.

posted on 2010-10-11 00:12  LeeXiaoLiang  阅读(329)  评论(0编辑  收藏  举报