FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index All products support nserialhd()
Posts: 340
Joined: Thu Jan 25, 2007 03:53 PM
nserialhd()
Posted: Thu Sep 13, 2012 05:57 PM

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

Posts: 1445
Joined: Mon Oct 10, 2005 02:38 PM
Re: nserialhd()
Posted: Thu Sep 13, 2012 09:47 PM
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 (fw): Select all Collapse
/* ***********************************************************************
   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 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home

Posts: 340
Joined: Thu Jan 25, 2007 03:53 PM
Re: nserialhd()
Posted: Fri Sep 14, 2012 03:51 PM

many thanks !

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

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

tks

Romeo

Posts: 1445
Joined: Mon Oct 10, 2005 02:38 PM
Re: nserialhd()
Posted: Fri Sep 14, 2012 06:22 PM
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 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home

Posts: 340
Joined: Thu Jan 25, 2007 03:53 PM
Re: nserialhd()
Posted: Mon Sep 17, 2012 02:33 PM

tks any

Continue the discussion