nserialhd()

Moderator: Enrico Maria Giordano

Post Reply
Romeo
Posts: 328
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

nserialhd()

Post by Romeo »

Ciao,

sai se esiste qualche funzione similare a nserialhd() che mi da un identificazione unica di u HD o di un una Pendrive Usb ?

Poiche' nserialhd() varia ogni volta che formatto l'unità

Romeo/zingoni
FiveWiDi
Posts: 910
Joined: Mon Oct 10, 2005 2:38 pm

Re: nserialhd()

Post by FiveWiDi »

Romeo wrote:Ciao,

sai se esiste qualche funzione similare a nserialhd() che mi da un identificazione unica di u HD o di un una Pendrive Usb ?

Poiche' nserialhd() varia ogni volta che formatto l'unità

Romeo/zingoni
Quizás te sirva.

Code: Select all

/* ***********************************************************************
   A partir d'una lletra d'un USB inicia la cerca del seu número de sèrie.
   -------------------------------------------------------------------- */
STATIC FUNCTION GetUSBSerial( cDrive )
Local oLoc := CreateObject( "wbemScripting.SwbemLocator" )
Local oSrv := oLoc:ConnectServer()
Local oJobs := oSrv:ExecQuery( "SELECT * FROM Win32_LogicalDiskToPartition" )
Local oJob
Local cDriveNumber

cDrive = Upper( cDrive )
If Len( cDrive ) == 1
    cDrive += ":"
Endif
If Len( cDrive ) > 2
    cDrive = SubStr( cDrive, 1, 2 )
Endif

For each oJob in oJobs

    If cDrive == StrToken( oJob:Dependent, 2, '"' )
        cDriveNumber = SubStr( StrToken( StrToken( oJob:Antecedent, 2, '"' ), 1, "," ), 7 )

        return GetSerial( oSrv, cDriveNumber )
    Endif
Next

Return "."
/* *************************** */
/* *************************** */

/* *********************************************************
   Cerca a partir d'una lletra d'USB el seu número de sèrie.
   ------------------------------------------------------ */
STATIC FUNCTION GetSerial( oSrv, cDriveNumber )
Local aDrives := oSrv:ExecQuery( "SELECT * FROM Win32_DiskDrive" )
Local oDrive, cSerial := ""

For each oDrive in aDrives
    If oDrive:Name == "\\.\PHYSICALDRIVE" + cDriveNumber .and. ;
       oDrive:InterfaceType == "USB"

        cSerial = oDrive:PNPDeviceID

        cSerial = SubStr( cSerial, 1, RAt( "&", cSerial ) - 1 )
        cSerial = SubStr( cSerial, RAt( "&", cSerial ) + 1 )
        If At( "\", cSerial ) != 0
            cSerial = SubStr( cSerial, At( "\", cSerial ) + 1 )
        Endif

        Return cSerial
        //Exit
    Endif
Next

Return cSerial
/* *************************** */
Un Saludo
Carlos G.

FiveWin 19.06 + Harbour 3.2, BCC 7 Windows 10
Romeo
Posts: 328
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: nserialhd()

Post by Romeo »

many thanks !

Can also you help me to set a serial in USBdrive ?

example:
setserialusb("G:","123456789") ?

tks

Romeo
FiveWiDi
Posts: 910
Joined: Mon Oct 10, 2005 2:38 pm

Re: nserialhd()

Post by FiveWiDi »

Romeo wrote:many thanks !

Can also you help me to set a serial in USBdrive ?

example:
setserialusb("G:","123456789") ?

tks

Romeo
I think is not posible.
Un Saludo
Carlos G.

FiveWin 19.06 + Harbour 3.2, BCC 7 Windows 10
Romeo
Posts: 328
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: nserialhd()

Post by Romeo »

tks any
Post Reply