Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to get DOS Serial No. in VFP using WinAPI
Message
De
30/07/1999 04:36:46
 
 
À
30/07/1999 04:03:28
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00248061
Message ID:
00248074
Vues:
31
>declare integer GetVolumeInformation in win32api ;
> string rootdir, string @volumename, integer vnamesize,;
> string @volserial, integer a, integer b, string c, integer d
>CLEAR
>buf1 = NULL
>volserial = replicate(chr(0), 4)
>a = 0
>b = 0
>c = ""
>d = 0
>r = GetVolumeInformation(buf1,@volumename,vnamesize,;
> @volserial,a,b,c,d)
>
>? "Volserial: "
>v12 = ctobin( allt(volserial) )
>? v12
>t = tran(ctobin(allt(volserial) ),"@0")
>t = strt(t,"0x","")
>? t
>? ""
>?? substr(t,7,2)
>?? substr(t,5,2)+"-"
>?? substr(t,3,2)
>?? substr(t,1,2)

The code doesn't work properly; you've omitted a couple of key variable initialization (volumename and vnamesize) and ctobin doesn't do the conversion properly, since alters the range of values represented by a 4 byte integer type. The code in both the drive type classes handle the conversion properly.

The following modifications will make your code work, but it's probably better to use one of the classes in the Files Section:

declare integer GetVolumeInformation in win32api ;
string rootdir, string @volumename, integer vnamesize,;
integer @ volserial, integer a, integer b, string c, integer d
* note the difference - I have the API pass back an integer for volserial directly
CLEAR
buf1 = NULL && if not null, this needs to be drive letter: + chr(0)
* additional init variables needed
volumename = space(254)
vnamesize = 254
*decalre volserial as a numeric
volserial = 0
a = 0
b = 0
c = ""
d = 0
r = GetVolumeInformation(buf1,@volumename,vnamesize,;
@volserial,a,b,c,d)

? "Volserial: "
* note: no CTOBIN needed
? volserial
t = tran(volserial,"@0")
t = strt(t,"0x","")
? t
? ""
* Note - no byte reversal needed
? left(t,4) + '-' + right(t,4)
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform