
FUNCTION verif_ser_perm
CLEAR
?PORNIRE()
Function pornire
Set Exact On
Private calewin,calesys,checksum1,checksum2,serinreg,serdisk,file1,file2,valret,serdisktemp
Store '' To calewin,serinreg,serdisk,calesys,serdisktemp,catehd
Store 0 To checksum1,checksum2
Store .T. To valret
Declare Integer SHGetFolderPath In SHFOLDER.Dll ;
	INTEGER hwndOwner, ;
	INTEGER nFolder, ;
	INTEGER hToken, ;
	INTEGER dwFlags, ;
	STRING @ pszPath
Declare Integer GetActiveWindow In WIN32API
#Define CSIDL_WINDOWS  36
#Define CSIDL_SYSTEM   37
#Define CSIDL_PROGRAMS 38
lcPath = Repl(Chr(0),261)
=SHGetFolderPath(GetActiveWindow(),CSIDL_WINDOWS,0,0,@lcPath)
calewin=Left(lcPath,At(Chr(0),lcPath)-1)
lcPath = Repl(Chr(0),261)
=SHGetFolderPath(GetActiveWindow(),CSIDL_SYSTEM,0,0,@lcPath)
calesys=Left(lcPath,At(Chr(0),lcPath)-1)
&&se verifica existenta celor trei fisiere
If (Not File(calesys+'\diskserial.dll')) Or (Not File(calesys+'\getmacip.dll')) Or (Not File(calewin+'\comdir.snr'))
	valret=.F.
Endif
If valret
	file1=Filetostr(calesys+'\diskserial.dll')
	checksum1=Sys(2007,file1)
	file2=Filetostr(calesys+'\getmacip.dll')
	checksum2=Sys(2007,file2)
	If (VAL(checksum1) != 58755) Or (VAL(checksum2) != 30476)
		valret=.F.
	Endif
Endif
If valret
	Declare Integer GetSerialNumber In diskSerial.Dll Integer ,String
	serdisktemp=Space(40)
	catehd=0
	For i=0 To 3
		GetSerialNumber(i,@serdisktemp)
		If (Len(Alltrim(serdisktemp))!=0) And catehd=0
			serdisk=Substr(Alltrim(serdisktemp),Len(Alltrim(serdisktemp))-8,8)
			serdisk=Upper(serdisk)
			catehd=catehd+1
		Endif
	Endfor
Endif
If valret
	gnFileHandle = Fopen(calewin+'\comdir.snr')
	nSize =  Fseek(gnFileHandle, 0, 2)     && Move pointer to EOF
	If nSize<8
		valret=.F.
	Else
		= Fseek(gnFileHandle, 0, 0)      && Move pointer to BOF
		cString = Fread(gnFileHandle,8)
		serinreg=DECODARE1(Alltrim(Upper(cString)))
		If serdisk!=serinreg
			valret=.F.
		Endif
	Endif
	= Fclose(gnFileHandle)
Endif
On Error valret=.F.
Return valret
*************
FUNCTION decodare1 
PARAMETERS lstring
LOCAL lens,poz1,poz2,lret,lcstring,val1
lret=''
lcstring=ALLTRIM(UPPER(lstring))
lens=LEN(lcstring)
FOR i=1 TO lens
poz1=SUBSTR(lcstring,i,1)
val1=ASC(poz1)
DO CASE 
CASE val1>=48 AND val1<=57
 poz2=CHR(val1+33)&& din 0-9 in Q-Z
CASE val1>=81 AND val1<=90
 poz2=CHR(val1-33)&& din Q-Z in 0-9
CASE val1>=65 AND val1<=72
 poz2=CHR(val1+8)&&din K-R in S-Z
CASE val1>=73 AND val1<=80
 poz2=CHR(val1-8)&&din S-Z in K-R
ENDCASE
lret=lret+poz2
endfor
RETURN lret

