Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: naveed ahmad
  Where is naveed ahmad?
 peshawar
 Pakistan
 naveed ahmad
 To: Pete Sass
  Where is Pete Sass?
 Marathon, Ontario
 Canada
 Pete Sass
 Tags
Subject: RE: Hard Disk Serial Number Problem
Thread ID: 393678 Message ID: 393680 # Views: 48 # Ratings: 0
Version: Visual FoxPro 9 Category: Forms
Date: Saturday, December 21, 2013 2:39:56 PM         
   


> > hi Experts.
> > its problem repeated many times and i have tried many queries but didn't get a proper result.
> > when i check it my system it works proper but when i copy another system then not work, please help me to solve it.
> > i am using following codes
> >
> > Create Cursor myDisks (DriveLetter c(1),SerialNumber c(50),Model c(50),DeviceID c(50),VolumeName c(50),VolumeSerialNumber c(20))
> >
> > wmiServices = Getobject("winmgmts:{impersonationLevel=Impersonate}!//.")
> > wmiDiskDrives = wmiServices.ExecQuery("SELECT Model,DeviceID FROM Win32_DiskDrive")
> >
> > For Each wmiDiskDrive In wmiDiskDrives
> > lcDeviceID = Trim(Strtran(wmiDiskDrive.DeviceID,'\','\\'))
> > wmiDiskPartitions = wmiServices.ExecQuery(;
> > 'ASSOCIATORS OF {Win32_DiskDrive.DeviceID="' +;
> > m.lcDeviceID + '"} WHERE '+ ;
> > 'AssocClass = Win32_DiskDriveToDiskPartition')
> >
> > For Each wmiDiskPartition In wmiDiskPartitions
> > wmiLogicalDisks = wmiServices.ExecQuery( ;
> > 'ASSOCIATORS OF {Win32_DiskPartition.DeviceID="'+;
> > wmiDiskPartition.DeviceID + '"} WHERE '+;
> > 'AssocClass = Win32_LogicalDiskToPartition')
> >
> > For Each wmiLogicalDisk In wmiLogicalDisks
> > wmiDiskVolumes = wmiServices.ExecQuery(;
> > "Select deviceID,VolumeName,VolumeSerialNumber from Win32_LogicalDisk"+;
> > " where deviceID = '" + wmiLogicalDisk.deviceID + "'" )
> > For Each oVolume In wmiDiskVolumes
> > lcVolumeName = oVolume.VolumeName
> > lcVolumeSerialNumber = oVolume.VolumeSerialNumber
> > Exit
> > Endfor
> >
> > wmiDisks = wmiServices.ExecQuery(;
> > 'SELECT * FROM Win32_PhysicalMedia where Tag="'+m.lcDeviceID+'"')
> > For Each wmiDisk In wmiDisks
> > Insert Into myDisks ;
> > (DriveLetter,SerialNumber,Model,DeviceID,VolumeName,VolumeSerialNumber) ;
> > values ;
> > (wmiLogicalDisk.DeviceID,;
> > wmiDisk.SerialNumber,;
> > wmiDiskDrive.Model,;
> > wmiDiskDrive.DeviceID,;
> > m.lcVolumeName,;
> > m.lcVolumeSerialNumber)
> > Endfor
> > Endfor
> > Endfor
> > Endfor
> >
> > regards.
>
>
> Hi,
>
> Please try my code example below and advise if this works as expected:
>
* --- GetHDInfo.prg
> loWBEMLocator = Createobject("wbemScripting.SwbemLocator")
> loWMIService = loWBEMLocator.ConnectServer('', '\root\cimv2')
> 
> CREATE CURSOR curHDDinfo (TYPES c(24), DESCRIPTIONS c(24), DEVICEIDENTIFIER c(24), VOLNAMES c(24) NULL, SERIALNOS c(36) NULL, DRIVETAGS c(36) NULL)
> IF !ISNULL(loWMIService)
>   loLogicalDrives = loWMIService.ExecQuery('Select * from Win32_LogicalDisk')
>   For Each loLogicalDrive In loLogicalDrives
>      INSERT INTO curHDDINFO (TYPES,DESCRIPTIONS,DEVICEIDENTIFIER,VOLNAMES,SERIALNOS,DRIVETAGS) ;
>      VALUES("LOGICAL DISK",ALLTRIM(loLogicalDrive.Description),ALLTRIM(loLogicalDrive.DeviceID), ;
>      ALLTRIM(loLogicalDrive.VolumeName),ALLTRIM(loLogicalDrive.VolumeSerialNumber),"")
>    Endfor
>  
>   loPhysicalDrives = loWMIService.ExecQuery('Select * from Win32_PhysicalMedia')
>   For Each loPhysicalDrive In loPhysicalDrives
>     INSERT INTO curHDDINFO (TYPES,SERIALNOS,DRIVETAGS) VALUES ("PHYSICAL DISK",ALLTRIM(loPhysicalDrive.Tag),ALLTRIM(loPhysicalDrive.SerialNumber))
>   Endfor
> ENDIF
> 
> * --- Browse the local cursor to review the obtain results
> * --- Starr out three lines of code below to process the cursor for logical code operatings.
> GOTO TOP
> * --- BROWSE STARRED OUT FOR DEBUGGING PURPOSES ONLY.
> * --- BROWSE 
> LOCATE FOR ALLTRIM(DEVICEIDENTIFIER) == "C:"
> lcHDSerialNo = ALLTRIM(SERIALNOS)
> 
> * --- Issue USE to close this local cursor.
> USE
> 
> * --- Return the C:\ drives serial number.
> RETURN lcHDSerialNo

>
>
>
>
> You can un-star the line * --- BROWSE and see what drive information you are obtaining.
> Set the code line below:
>
LOCATE FOR ALLTRIM(DEVICEIDENTIFIER) == "C:"

> to set what drive letter you want to get the serial number for.
>
>
>
>
> Pete "the IceMan", from the Great White North of Canada.
> www.marathongriffincomputers.com

dear sir,
thanks for reply, i have tried your code also but same result, i made form where have one textbox and one button i code on button click event it works my system very well but not respond another system. please guide me what should i do for this problem.
thanks a lot.
regards

ENTIRE THREAD

Hard Disk Serial Number Problem Posted by naveed ahmad @ 12/21/2013 1:58:34 PM
RE: Hard Disk Serial Number Problem Posted by Pete Sass @ 12/21/2013 2:32:54 PM
RE: Hard Disk Serial Number Problem Posted by naveed ahmad @ 12/21/2013 2:39:56 PM
RE: Hard Disk Serial Number Problem Posted by Pete Sass @ 12/21/2013 4:05:43 PM
RE: Hard Disk Serial Number Problem Posted by naveed ahmad @ 12/23/2013 8:35:33 AM
RE: Hard Disk Serial Number Problem Posted by Pete Sass @ 12/23/2013 2:51:58 PM
RE: Hard Disk Serial Number Problem Posted by naveed ahmad @ 12/23/2013 3:22:47 PM
RE: Hard Disk Serial Number Problem Posted by Pete Sass @ 12/24/2013 8:11:42 PM
RE: Hard Disk Serial Number Problem Posted by Tore Bleken @ 12/21/2013 6:24:19 PM
RE: Hard Disk Serial Number Problem Posted by naveed ahmad @ 12/23/2013 8:32:47 AM