AutoHotkey Community

It is currently May 25th, 2012, 8:49 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 44 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: HDD
PostPosted: November 7th, 2007, 7:48 am 
I have found this DLL for get HDD serial no but I am new in AHK I don’t know the method of Call a DLL is there anyone who can test this DLL and give me the code.

Sorry for bad English

Thanks a lot in advance.

http://rapidshare.com/files/67997092/Ge ... l.dll.html


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2007, 3:44 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
people are not likely to download a random dll from rapidshare - do you have the original link where you found it?

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2007, 4:54 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
You can download it from the trusted SoftPedia: http://www.softpedia.com/progDownload/GetDiskSerial-DLL-Download-23473.html, but it is shareware, you have to register for $15. Why bother? There are free tools, just search the Forum.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2007, 10:58 pm 
Laszlo wrote:
You can download it from the trusted SoftPedia: http://www.softpedia.com/progDownload/GetDiskSerial-DLL-Download-23473.html, but it is shareware, you have to register for $15. Why bother? There are free tools, just search the Forum.


I searched and didn't find a Dll solution for this. Most of what I found were command line utilities or only returned the volume serial number, not the serial number the manufacturer gives the drive that cannot be changed by formatting.

Here is a link to the page for the DLL from the original developers:
http://www.devlib.net/getdiskserial.htm

I read through some of the examples provided and came up with this:
Code:
RegCode := 000000000000
Drive   := 0

hModule := DllCall("LoadLibrary", "Str", "GetDiskSerial.dll")

Serial := DllCall("GetDiskSerial\GetSerialNumber", Int, Drive, Str, RegCode)

Model := DllCall("GetDiskSerial\GetModelNumber", Int, Drive, Str, RegCode)

Revision := DllCall("GetDiskSerial\GetRevisionNo", Int, Drive, Str, RegCode)

Buffer := DllCall("GetDiskSerial\GetBufferSize", Int, Drive, Str, RegCode)

Cylinders := DllCall("GetDiskSerial\GetCylinders", Int, Drive, Str, RegCode)

Heads := DllCall("GetDiskSerial\GetHeads", Int, Drive, Str, RegCode)

Sectors := DllCall("GetDiskSerial\GetSectors", Int, Drive, Str, RegCode)

DllCall("FreeLibrary", "UInt", hModule)

MsgBox Serial: %Serial%`nModel: %Model%`nRevision: %Revision%`nBuffer: %Buffer%`nCylinders: %Cylinders%`nHeads: %Heads%`nSectors: %Sectors%


GetSerialNumber, GetModelNumber and GetRevisionNo all return a code (I guess an error code? A Google search didn't really turn up anything...) but not what they should. The rest seem to return the correct values.

I don't know if it is a limitation on the shareware version or if I am just calling the first 3 functions wrong. You get a message box every time you call a function asking if you want to register the Dll, so I don't see why the functions wouldn't return what they are supposed to.

Looking into it a little better it might be possible to do this with AHK alone using Sean's CoHelper and the WMI API. That's over my head :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2007, 12:09 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
If you have Intel chipset, you can use the free Matrix Storage Manager, http://downloadcenter.intel.com/Product_Filter.aspx?ProductID=2101. It is a standalone program, but can save the system report in a file, which you can delete from your script after use. It works with RAID, too, giving all the individual disk serial numbers. Other controller manufacturers could have similar tools.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2007, 12:29 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
I thought I had done it already but I failed to find it. Anyway here is one.
WMI should be enabled in the system and need the latest Standard Library COM.ahk.
May have to use Win32_DiskDrive instead of Win32_PhysicalMedia in Vista.

Code:
COM_Init()
MsgBox, % WMI_Query("root\cimv2", "Win32_PhysicalMedia", "SerialNumber")
;   . WMI_Query("root\cimv2", "Win32_DiskDrive", "Model")
COM_Term()
Return

WMI_Query(Namespace, Class, Property)
{
   psvc :=   COM_GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\" . Namespace)
   pset :=   COM_Invoke(psvc, "ExecQuery", "SELECT * FROM " . Class)
   penm :=   COM_Invoke(pset, "_NewEnum")
   Loop
      If   COM_Enumerate(penm, pobj) = 0
         sRes .=   Property . " = " . COM_Invoke(pitm:=COM_Invoke(pprs:=COM_Invoke(pobj, "Properties_"), "Item", Property), "Value") . SubStr(COM_Release(pitm) . COM_Release(pprs) . COM_Release(pobj),1,0) . "`n"
      Else   Break
   COM_Release(penm)
   COM_Release(pset)
   COM_Release(psvc)
   Return   sRes
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2007, 3:47 am 
Laszlo wrote:
If you have Intel chipset, you can use the free Matrix Storage Manager, http://downloadcenter.intel.com/Product_Filter.aspx?ProductID=2101. It is a standalone program, but can save the system report in a file, which you can delete from your script after use. It works with RAID, too, giving all the individual disk serial numbers. Other controller manufacturers could have similar tools.


I'm not sure about all that. It would add a lot of baggage, or at least it seems like it would to me. The thread starter might be more willing to go this route though.

Sean wrote:
I thought I had done it already but I failed to find it. Anyway here is one.
WMI should be enabled in the system and need the latest Standard Library COM.ahk.
May have to use Win32_DiskDrive instead of Win32_PhysicalMedia in Vista.


Thanks, works flawlessly on my XP Home desktop! :)

But my laptop is another matter. It is running Vista Home Premium on a SCSI hard drive. The Dll posted above doesn't work at all on it using the demo programs from the examples. And the script you posted returns 16 for serial number. I tried both Win32_PhysicalMedia and Win32_DiskDrive and got the same results. Maybe 16 is the serial number. It's a HP laptop so I guess anything is possible.

But it would be nice if http://www.devlib.net would mention on that page that the $15 Dll will not work on SCSI drives. :roll:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2007, 4:21 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
I also tried Sean’s script in my big Vista PC, with a 4-disk SATA RAID. It only shows the name of the RAID, I gave it at creation, but no valid disk serial numbers (all 4 are displayed as 16). The Intel Matrix Storage Console shows the name of the RAID as “Volume Number”, and shows the real serial number of each disk, too.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2007, 7:10 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
I can't really tell about Vista as I don't have an experience with it. As my wife has a laptop (which is also HP!) with Vista (Home Premium too, I think) I may take a look, but I've become to avoid inspecting other's machines.
Anyway, looks like it's Vista's UAC issue:
http://msdn2.microsoft.com/en-us/library/aa826699.aspx


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2007, 7:44 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
MSDN wrote:
SerialNumber
Data type: string
Access type: Read-only

Number allocated by the manufacturer to identify the physical media.

Example: WD-WM3493798728

Windows Server 2003, Windows XP, Windows 2000, and Windows NT 4.0: This property is not available.
We see problems also with Vista, so I wonder if the disk Serial Number is available to Windows, at all. A search in my registry does not find it, either.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2007, 12:17 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Laszlo wrote:
We see problems also with Vista, so I wonder if the disk Serial Number is available to Windows, at all. A search in my registry does not find it, either.

Does diskid32.exe return the correct results in Vista? If so, can use DeviceIoControl instead.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2007, 1:11 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Diskid32 does not produce any output in my Vista PC. It briefly pops up a console window, but no output is visible. Redirecting the output to a file does not work, either.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2007, 2:24 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Laszlo wrote:
Diskid32 does not produce any output in my Vista PC. It briefly pops up a console window, but no output is visible. Redirecting the output to a file does not work, either.

I'm not sure if it's an issue of Vista or RAID. As there is no mention about RAID in diskid32 page, I suspect it may not work with RAID. I can't tell atm whether DeviceIoControl is still applicable with RAID or not.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2007, 9:23 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Zippo() wrote:
But my laptop is another matter. It is running Vista Home Premium on a SCSI hard drive.

Could you try the following code? Your HDD is SCSI, but obviously not RAID, so the code might work.

Code:
idxDrv   := 0 ; 1, 2, etc
If Not   1 + hDrive:=DllCall("CreateFile", "str", "\\.\PhysicalDrive" . idxDrv, "Uint", 0, "Uint", 3, "Uint", 0, "Uint", 3, "Uint", 0, "Uint", 0)
   ExitApp

VarSetCapacity(qr,12,0), VarSetCapacity(dd,8,0)
; IOCTL_STORAGE_QUERY_PROPERTY
If   DllCall("DeviceIoControl", "Uint", hDrive, "Uint", 0x002D1400, "Uint", &qr, "Uint", VarSetCapacity(qr), "Uint", &dd, "Uint", VarSetCapacity(dd), "UintP", nReturn, "Uint", 0)
&&   VarSetCapacity(dd,NumGet(dd,4))
&&   DllCall("DeviceIoControl", "Uint", hDrive, "Uint", 0x002D1400, "Uint", &qr, "Uint", VarSetCapacity(qr), "Uint", &dd, "Uint", VarSetCapacity(dd), "UintP", nReturn, "Uint", 0)
   MsgBox, % ((nOff:=NumGet(dd,24,"int"))<>-1 ? "Serial Number:`t""" . DecodeSN(DllCall("msvcrt\abs", "int", &dd+nOff, "Cdecl Str")) . """`n" : "")
      . ((nOff:=NumGet(dd,16)) ? "Model Number:`t""" . DllCall("msvcrt\abs", "int", &dd+nOff, "Cdecl Str") . """`n" : "")
      . ((nOff:=NumGet(dd,20)) ? "Revision Number:`t""" . DllCall("msvcrt\abs", "int", &dd+nOff, "Cdecl Str") . """`n" : "")

DllCall("CloseHandle", "Uint", hDrive)
Return

DecodeSN(h)
{
   Loop, %   StrLen(h)//4
      SN .= Chr("0x" . SubStr(h,4*A_Index-1,2)) . Chr("0x" . SubStr(h,4*A_Index-3,2))
   Return   SN
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2007, 11:05 am 
Sean wrote:
Could you try the following code? Your HDD is SCSI, but obviously not RAID, so the code might work.


Ran it, got this:
Quote:
Serial Number: ""
Model Number: "1AS "
Revision Number: "7.24"


I see that you used IOCTL_STORAGE_QUERY_PROPERTY in that script. I was looking into IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER after seeing it mentioned in that diskid32.exe link you posted above, but I didn't get a chance today to make a script and test it.

BTW, I compiled the script and ran it as Admin to see if that made a difference, but no change.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 44 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google Feedfetcher, krajan, MilesAhead, Rathgar2, rbrtryn, vsub and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group