AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

HDD
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
sara
Guest





PostPosted: Wed Nov 07, 2007 6:48 am    Post subject: HDD Reply with quote

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/GetDiskSerial.dll.html
Back to top
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Wed Nov 07, 2007 2:44 pm    Post subject: Reply with quote

people are not likely to download a random dll from rapidshare - do you have the original link where you found it?
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Wed Nov 07, 2007 3:54 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Zippo()
Guest





PostPosted: Wed Nov 07, 2007 9:58 pm    Post subject: Reply with quote

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 Smile
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Wed Nov 07, 2007 11:09 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1397

PostPosted: Wed Nov 07, 2007 11:29 pm    Post subject: Reply with quote

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
}
Back to top
View user's profile Send private message
Zippo()
Guest





PostPosted: Thu Nov 08, 2007 2:47 am    Post subject: Reply with quote

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! Smile

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. Rolling Eyes
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Thu Nov 08, 2007 3:21 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1397

PostPosted: Thu Nov 08, 2007 6:10 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Thu Nov 08, 2007 6:44 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1397

PostPosted: Thu Nov 08, 2007 11:17 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Fri Nov 09, 2007 12:11 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1397

PostPosted: Fri Nov 09, 2007 1:24 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1397

PostPosted: Fri Nov 09, 2007 8:23 am    Post subject: Reply with quote

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
}
Back to top
View user's profile Send private message
Zippo()
Guest





PostPosted: Fri Nov 09, 2007 10:05 am    Post subject: Reply with quote

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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group