nserialhd()

Moderator: Enrico Maria Giordano

nserialhd()

Postby Romeo » Thu Sep 13, 2012 5: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
Romeo
 
Posts: 340
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: nserialhd()

Postby FiveWiDi » Thu Sep 13, 2012 9: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: Select all  Expand view
/* ***********************************************************************
   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 24.02 + Harbour 3.2.0dev (r2403071241), BCC 7.7 Windows 10
FiveWiDi
 
Posts: 1048
Joined: Mon Oct 10, 2005 2:38 pm

Re: nserialhd()

Postby Romeo » Fri Sep 14, 2012 3:51 pm

many thanks !

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

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

tks

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

Re: nserialhd()

Postby FiveWiDi » Fri Sep 14, 2012 6: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 24.02 + Harbour 3.2.0dev (r2403071241), BCC 7.7 Windows 10
FiveWiDi
 
Posts: 1048
Joined: Mon Oct 10, 2005 2:38 pm

Re: nserialhd()

Postby Romeo » Mon Sep 17, 2012 2:33 pm

tks any
Romeo
 
Posts: 340
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)


Return to All products support

Who is online

Users browsing this forum: No registered users and 3 guests