PDA

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=&quot;font-family: Courier New&quot;>#ifdef _WIN32
#declareapi GetVolumeInformation kndll GetVolumeInformation 8 1

new(vserial$, tint);

GetVolumeInformation(&quot;C:\\&quot;, NULL, 0, &amp;vserial$, NULL, NULL, NULL, 0);

sprintf(serial$, &quot;0x%4X%4X&quot;, 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$ = &quot;&quot;;
GetComputerName(&amp;cpu$, 16);
return (cpu$);
end;

When I do this;
writeln(&quot;NetBios Name:&quot; + 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);
* &amp;cpu$ = &quot;&quot;;
* sz$ = MAX_COMPUTERNAME_LENGTH + 1;
* GetComputerName(&amp;cpu$, &amp;sz$);
* return(cpu$);
end;

This works, and I'm not sure exactly what fixed it, though I'd wager it was the &amp; 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.