hi all,
is there any function in qt that will get the hard disk serial number as well as its mac address? thnks a lot..
hi all,
is there any function in qt that will get the hard disk serial number as well as its mac address? thnks a lot..
No, there are no such functions in Qt. Use the native API.
thnks for the response.. can you give me any link or example on how to use the native API?
ok.. i'l check for it.. thnks..
hi all,
i have here a simple code to get the hard disk serial, using a function from msdn.
heres my code:
when i build my code an error occured..Qt Code:
#include <stdio.h> #include <windows.h> DWORD dwVolSerial; BOOL bIsRetrieved; int main() { bIsRetrieved = GetVolumeInformation("C:\\", NULL, NULL, &dwVolSerial, NULL, NULL, NULL, NULL); if (bIsRetrieved) { printf("Serial number of drive C is %X\n",dwVolSerial); } else { printf("Could not retrieve\n"); } return 0; }To copy to clipboard, switch view to plain text mode
Qt Code:
src\main.cpp:19: error: cannot convert `const char*' to `const WCHAR*' for argument `1' to `BOOL GetVolumeInformationW(const WCHAR*, WCHAR*, DWORD, DWORD*, DWORD*, DWORD*, WCHAR*, DWORD)'To copy to clipboard, switch view to plain text mode
is there anybody here knows how to solve this error?
thnks
Hi, try or to convert to WCHAR.
Ginsengelf
cutie.monkey (5th February 2009)
thnks.. its working..
another question, how can I convert DWORD dwVolSerial to string?
Qt Code:
DWORD dwVolSerial; printf("Serial number of drive C is %X\n",dwVolSerial); //returns Serial number of drive C is 5OB43BE To copy to clipboard, switch view to plain text mode
how can i get the exact return (5OB43BE)?
Please take a closer look at QString::number() docs. It takes an optional second parameter.
J-P Nurmi
cutie.monkey (6th February 2009)
Change the base to 16 (hex)
QString QString::number ( int n, int base = 16 )
default is decimal (10)
cutie.monkey (6th February 2009)
thnks. its finally working..
it's work for me
#include <qt_windows.h>
QString tdrive = "C:\\";
DWORD dwSerialNumber = 0;
bool ret = GetVolumeInformation((WCHAR *)tdrive.utf16(),NULL,NULL,&dwSerialNumber,NULL,NU LL,NULL,NULL);
if (ret) {
qDebug()<<"dwSerialNumber " << dwSerialNumber;
}
Waking up a four years dormant thread to provide an answer that was given a couple of times in the thread already. Some kind of record?
And how does this include file change the solution? You are effectively calling the same function. I don't know what qt_windows.h is but it probably contains a #include <windows.h> line.
The above code returns the HDD serial number assigned by the OS ! Is there another function to retrieve the physical one assigned by the manufacturer ?
msdn suggests using the Windows Management Instrumentation: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
Any ideas how to do it without this service ?
Thanks a lot !
PS: I hope it is ok using this old post, I figured it is best than opening a new one with the same topic
Last edited by mugi; 28th April 2014 at 15:59.
From the GetVolumeInformation() docs:
Win32_PhysicalMedia classThis function returns the volume serial number that the operating system assigns when a hard disk is formatted. To programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI) Win32_PhysicalMedia property SerialNumber.
WMI C++ Application Examples
Bookmarks