Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
HD serial number
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00936900
Message ID:
00937080
Vues:
12
If you are using Win XP or better, You can try WMI:
*-- Serial of HD 0 of local machine using current user's permissions:
?  GetHDSerial()

*-- Serial of HD 1 of remote machine "RMachine1"

? GetHDSerial(1, 'RMachine1', 'AdminUser', 'AdminPassword')

* Password must be Domain Admin password, or the password of an admin of the remote machine
* and WMI permissions must be set
*__________________________________________________



Function GetHDSerial(tnDevice, tcComputer, tcUser, tcPassword)

  Local lcComputer, loWMIService, loWBEMLocator, loNetWork, lcDomain
  Local loLocator, lcUser, lcPassword, lcDomain, loNetWork, lnDevice
  Local loDrives, loDrive, lnCurrDevice, lcSerial

  lcDomain = getenv("UserDomain")
  lcUser = Iif(Vartype(tcUser) = 'C', tcUser, '')
  lcPassword = Iif(Vartype(tcPassword) = 'C', tcPassword, '')
  lcComputer = Iif(Vartype(tcComputer) = 'C', tcComputer, '')
  lnDevice = Iif(Vartype(tnDevice) = 'N', tnDevice, 0)
  lcSerial = 'Unknown'

  Try
    loWBEMLocator = Createobject("wbemScripting.SwbemLocator")
    loWMIService = loWBEMLocator.ConnectServer(lcComputer, '\root\cimv2', lcDomain + "\" + lcUser, lcPassword)

  Catch
    loWMIService = Null
  Endtry

  If Not Isnull(loWMIService)
    loDrives = loWMIService.ExecQuery('Select SerialNumber from Win32_PhysicalMedia')
    lnCurrDevice = 0
    For Each loDrive In loDrives
      If lnCurrDevice = lnDevice
        lcSerial = loDrive.SerialNumber
        Exit
      Endif
      lnCurrDevice = lnCurrDevice + 1
    Endfor
  Endif
  Return Alltrim(lcSerial)
Endfunc
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform