RE: Disk Serial ID

new topic     » topic index » view thread      » older message » newer message

CK Lester wrote:
> 
> Thanks, Irv, but I forgot to specify that I need it for a Windows 
> program...
> 
 
CK,

This it something I posted to the old list.  It does not require 
Win32Lib.

-- start tested program --
include dll.e
include machine.e
include get.e

constant
   kernel32 = open_dll( "kernel32.dll" ),
   xGetVolumeInfo = define_c_func( kernel32, "GetVolumeInformationA", 
                   {C_POINTER, C_POINTER, C_UINT, C_POINTER, C_POINTER, 
C_POINTER, C_POINTER, C_UINT }, C_INT)

function getVolSerial( sequence root_dir )
-- Input: A string that contains the root directory of the volume to be 
described. 
--        A trailing backslash is required. For example, you would 
specify 
--        \\MyServer\MyShare as "\\\\MyServer\\MyShare\\", or the C 
drive as "C:\\". 
-- Output: Volume Serial Number

   atom rootPathName, volSerNum
   sequence ret_val

   rootPathName    = allocate_string( root_dir )
   volSerNum       = allocate( 4 )

   if not c_func( xGetVolumeInfo, { rootPathName, NULL, NULL, volSerNum,
                                   NULL, NULL, NULL, NULL } ) then
      puts( 1, "xGetVolumeInfo failed in function getVolSerial" )
   end if

   ret_val = { peek4u( volSerNum ) }
   free( rootPathName )
   free( volSerNum )

   return ret_val
  
end function

sn = sprintf( "%08x", getVolSerial( "C:\\" ) )
printf( 1, "Volume Serial Number is %s-%s", {sn[1..4],sn[5..8]} )
-- this can be verified by typing "vol" at the C: prompt
if wait_key() then end if

-- end tested program --

-- Brian

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu