Results 1 to 19 of 19

Thread: how to get harddisk serial?

  1. #1
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question how to get harddisk serial?

    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..

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to get harddisk serial?

    No, there are no such functions in Qt. Use the native API.

  3. #3
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get harddisk serial?

    thnks for the response.. can you give me any link or example on how to use the native API?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to get harddisk serial?


  5. #5
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get harddisk serial?

    ok.. i'l check for it.. thnks..

  6. #6
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get harddisk serial?

    hi all,

    i have here a simple code to get the hard disk serial, using a function from msdn.

    heres my code:
    Qt Code:
    1. #include <stdio.h>
    2. #include <windows.h>
    3.  
    4. DWORD dwVolSerial;
    5. BOOL bIsRetrieved;
    6.  
    7. int main() {
    8.  
    9. bIsRetrieved = GetVolumeInformation("C:\\", NULL, NULL, &dwVolSerial, NULL, NULL, NULL, NULL);
    10.  
    11.  
    12. if (bIsRetrieved) {
    13. printf("Serial number of drive C is %X\n",dwVolSerial);
    14. } else {
    15. printf("Could not retrieve\n");
    16. }
    17.  
    18. return 0;
    19. }
    To copy to clipboard, switch view to plain text mode 
    when i build my code an error occured..

    Qt Code:
    1. 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

  7. #7
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to get harddisk serial?

    Hi, try
    Qt Code:
    1. L"C:\\"
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. TEXT("C:\\")
    To copy to clipboard, switch view to plain text mode 
    to convert to WCHAR.

    Ginsengelf

  8. The following user says thank you to Ginsengelf for this useful post:

    cutie.monkey (5th February 2009)

  9. #8
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get harddisk serial?

    thnks.. its working..
    another question, how can I convert DWORD dwVolSerial to string?

  10. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to get harddisk serial?

    J-P Nurmi

  11. #10
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get harddisk serial?

    Qt Code:
    1. DWORD dwVolSerial;
    2. printf("Serial number of drive C is %X\n",dwVolSerial); //returns Serial number of drive C is 5OB43BE
    3.  
    4. QString::number(dwVolSerial) //returns 1353987262
    To copy to clipboard, switch view to plain text mode 

    how can i get the exact return (5OB43BE)?

  12. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to get harddisk serial?

    Please take a closer look at QString::number() docs. It takes an optional second parameter.
    J-P Nurmi

  13. The following user says thank you to jpn for this useful post:

    cutie.monkey (6th February 2009)

  14. #12
    Join Date
    Oct 2006
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to get harddisk serial?

    Change the base to 16 (hex)

    QString QString::number ( int n, int base = 16 )

    default is decimal (10)

  15. The following user says thank you to jbiloba for this useful post:

    cutie.monkey (6th February 2009)

  16. #13
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: how to get harddisk serial?

    thnks. its finally working..

  17. #14

    Default Re: how to get harddisk serial?

    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;
    }

  18. #15
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to get harddisk serial?

    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?

  19. #16

    Default Re: how to get harddisk serial?

    Quote Originally Posted by ChrisW67 View Post
    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?
    if you carefully read the topic, might notice that my solution is slightly different from the one proposed, see header file

  20. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to get harddisk serial?

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  21. #18
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to get harddisk serial?

    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.

  22. #19
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to get harddisk serial?

    From the GetVolumeInformation() docs:
    This 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.
    Win32_PhysicalMedia class
    WMI C++ Application Examples

Similar Threads

  1. serial port issues
    By jhowland in forum Qt Programming
    Replies: 7
    Last Post: 12th January 2009, 13:38
  2. accessing serial port without CONFIG += console
    By bnilsson in forum Qt Programming
    Replies: 2
    Last Post: 21st July 2008, 21:47
  3. serial communication programming
    By jagadish in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2007, 07:47
  4. Replies: 12
    Last Post: 23rd March 2007, 09:23
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.