View Full Version : Retrieve hard drive serial number on PC
kornalius
05-20-2008, 03:28 PM
Here is a little piece of code to retrieve the hard drive C: serial # in PPL. This code only works on the PC.
<span style="font-family: Courier New">#ifdef _WIN32
#declareapi GetVolumeInformation kndll GetVolumeInformation 8 1
new(vserial$, tint);
GetVolumeInformation("C:\\", NULL, 0, &vserial$, NULL, NULL, NULL, 0);
sprintf(serial$, "0x%4X%4X", HiWord(vserial$), LoWord(vserial$));
ShowMessage(serial$);
#endif</span>
Mike Halliday
05-20-2008, 05:17 PM
Hhhmm, I can see a great use for that!
Q: What is KNDLL? I have googled it, but not found anything useful. What is the equiv DLL file on the PPC?
PointOfLight
05-20-2008, 09:28 PM
kndll is a define which can be found in defs.ppl.* On the PC kndll is kernel32.dll.* On the PPC, it is coredll.dll (no, that's not a typo - it's just redundant :) )
Mike Halliday
05-20-2008, 10:20 PM
:) - should have known it would be that easy! :P
DirectDance
05-21-2008, 11:52 AM
Many thanks for this !
Perfect for implementing protection into our programs on PC.
Mike Halliday
06-13-2008, 01:29 PM
Alain, I need a few pointers on how the above works;
I have the following code;
#declareapi GetComputerName kndll GetComputerName 2 1
func ComputerName()
new(cpu$,16);
cpu$ = "";
GetComputerName(&cpu$, 16);
return (cpu$);
end;
When I do this;
writeln("NetBios Name:" + ComputerName());
I can an access violation error.
What have I done wrong? I have searched the net on how Kernel32 functions work and thought I had it right?
Cheers
PointOfLight
06-13-2008, 05:00 PM
Here's a revised version of your function:
#define MAX_COMPUTERNAME_LENGTH 15
func ComputerName()
* new(sz$, TLong);
* new(cpu$,MAX_COMPUTERNAME_LENGTH + 1);
* &cpu$ = "";
* sz$ = MAX_COMPUTERNAME_LENGTH + 1;
* GetComputerName(&cpu$, &sz$);
* return(cpu$);
end;
This works, and I'm not sure exactly what fixed it, though I'd wager it was the & in front of cpu$ when doing the initial assignment.
Mike Halliday
06-13-2008, 07:07 PM
Oh I see what I did wrong. (I think) - I will have a go at some more dll calls and see if I can work it out from yout code.
Thanks Eric.
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.