1. Serial ID from Win32
- Posted by Ck Lester <cklester at YAHOO.COM> Dec 04, 2000
- 482 views
I can get a disk serial ID from DOS, but how would I do that using a Win32 function? (The DOS library uses allocate_low(), which isn't allowed in the Win32 environment!) Thanks! <\<
2. Re: Serial ID from Win32
- Posted by Brian Broker <bkb at CNW.COM> Dec 04, 2000
- 480 views
On Mon, 4 Dec 2000 13:46:26 -0500, Ck Lester wrote: >I can get a disk serial ID from DOS, but how would I do that using a Win32 >function? (The DOS library uses allocate_low(), which isn't allowed in the >Win32 environment!) > >Thanks! ><\< Are you referring to a 'Volume Serial Number'? If so, then you'll want to use 'GetVolumeInformation' in 'kernel32.dll'. I don't know if there is an existing library that already has this function wrapped. Let me know if you need any assistance in using it. -- Brian
3. Re: Serial ID from Win32
- Posted by Ck Lester <cklester at YAHOO.COM> Dec 04, 2000
- 475 views
Brian, Yes, Volume Serial Number. Since I have no idea how to wrap a DLL function, I'll need an existing function from an existing library... If you can provide some code I can just plug into my app, please do! Thanks! ck P.S. I've got a VBA version if that would help. On Mon, 4 Dec 2000 14:54:43 -0500, Brian Broker <bkb at CNW.COM> wrote: >On Mon, 4 Dec 2000 13:46:26 -0500, Ck Lester wrote: > >>I can get a disk serial ID from DOS, but how would I do that using a Win32 >>function? (The DOS library uses allocate_low(), which isn't allowed in the >>Win32 environment!) >> >>Thanks! >><\< > > >Are you referring to a 'Volume Serial Number'? If so, then you'll want to >use 'GetVolumeInformation' in 'kernel32.dll'. I don't know if there is an >existing library that already has this function wrapped. Let me know if >you need any assistance in using it. > >-- Brian
4. Re: Serial ID from Win32
- Posted by Brian Broker <bkb at CNW.COM> Dec 04, 2000
- 440 views
On Mon, 4 Dec 2000 15:04:16 -0500, Ck Lester wrote: >Brian, > >Yes, Volume Serial Number. Since I have no idea how to wrap a DLL function, >I'll need an existing function from an existing library... > >If you can provide some code I can just plug into my app, please do! > >Thanks! >ck OK, here you go... plug and chug away: --------------------------------------- include win32lib.ew constant xGetVolumeInfo = linkFunc( 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 mset, rootPathName, volSerNum, ret_val mset = new_memset() rootPathName = acquire_mem( mset, root_dir ) volSerNum = acquire_mem( mset, DWord ) if not c_func( xGetVolumeInfo, { rootPathName, NULL, NULL, volSerNum, NULL, NULL, NULL, NULL } ) then warnErr( "xGetVolumeInfo failed in function getVolSerial" ) end if ret_val = peek4u( volSerNum ) release_mem( mset ) return ret_val end function -- the following two lines are a test and can be deleted -- printf( 1, "Volume Serial Number: %x", getVolSerial( "C:\\" ) ) -- this can be verified by typing "vol" at the C: prompt if wait_key() then end if --------------------------------------- -- Questions? Comments? -- just let me know... -- Brian
5. Re: Serial ID from Win32
- Posted by Brian Broker <bkb at CNW.COM> Dec 04, 2000
- 432 views
Ck, One comment on the code I sent. Due to the changing memory management routines in Win32Lib, this will require the most recent version available. I used version 0.54.5... -- Brian
6. Re: Serial ID from Win32
- Posted by Ck Lester <cklester at YAHOO.COM> Dec 04, 2000
- 430 views
- Last edited Dec 05, 2000
Brian, thanks a bazillion. I'm at home right now, but I'll plug this stuff in tomorrow at work and see how it goes. BTW, what would I need to do if I didn't want to include Win32Lib? How much does that add to a final executable? Just curious, as the particular program for which this is needed is for my own use in creating programs for others to use... Thanks, again! <\< On Mon, 4 Dec 2000 17:39:14 -0500, Brian Broker <bkb at CNW.COM> wrote: >--------------------------------------- >-- Questions? Comments? >-- just let me know... >-- Brian
7. Re: Serial ID from Win32
- Posted by Brian Broker <bkb at CNW.COM> Dec 04, 2000
- 438 views
- Last edited Dec 05, 2000
On Mon, 4 Dec 2000 19:18:04 -0500, Ck Lester wrote: >Brian, thanks a bazillion. I'm at home right now, but I'll plug this stuff >in tomorrow at work and see how it goes. > >BTW, what would I need to do if I didn't want to include Win32Lib? How much >does that add to a final executable? Just curious, as the particular >program for which this is needed is for my own use in creating programs for >others to use... > >Thanks, again! Bad habit of mine to assume that a Windows question means using Win32Lib... Here it is without using Win32Lib (i.e. less error checking): ------------------------------------------------------- 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 ------------------------------------------------------- -- the following lines are a test and can be deleted -- sequence sn 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 ------------------------------- -- hope this is better for you -- let me know if you'd also like to get the Volume Label with this... -- (you can easily emulate the 'vol' command with this function) -- Brian