none
Harddrive serial info RRS feed

  • Question

  • I have been searching on the forums and over the web looking on how to get infromation from your harddrive(s) but cant really find any info about it.

    Does anyone know how i might because to get hardriver model & serial number?
    Sunday, September 14, 2008 10:51 PM

Answers

  • Stefanlg:

    You do not seem to have learned much from what I tried to teach you yesterday. Rupesh Shukla has given you what he believes to be the answer. You respond that you tried it but you cannot get it to work right. What is Rupesh supposed to do now?

    Describe what you did
    Describe what happened
    Describe what you expected to happen

    In any case, this question is not about the C++ language, so it is in the wrong forum.

    David Wilkinson | Visual C++ MVP
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:33 AM
    Monday, September 15, 2008 9:26 PM
  • Stefanlg:

    Well, all these errors are the same. There is no need to dump them all on us. Just look at the first one. The compiler says that the struct
    _GETVERSIONINPARAMS has been defined twice. And it tells you where those two places are. So why don't you try to figure out why this is happening?

    Only you have access to all this information.


    David Wilkinson | Visual C++ MVP
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:33 AM
    Monday, September 15, 2008 10:13 PM
  • Stefanlg:

    I hate to keep nagging you, but you are really not using the forums effectively. There is no reason to post code with glaring compiler errors; as ildjarn says, this example does not even look like C++.

    Either you are interested in solving your problems or you are not. If you are not, you should not be bothering the people in these forums. If you are, surely it has to be more efficient for you to make some reasonable attempt to solve your problem yourself. This particular issue of drive info you first raised two days ago, and you have not really made much progress, because very time you get stuck you post some poorly thought out question.

    Asking a question in the forums should be the last resort, not the first resort.






    David Wilkinson | Visual C++ MVP
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:34 AM
    Tuesday, September 16, 2008 9:40 PM
  • Stefanlg:

    Did you read the documentation on GetVolumeInformation? The BOOL (not bool) return value just indicates whether the function succeeded. The volume information is returned in the other parameters.

    By the way, you do not need the (LPWSTR) casts in your code, and you should get rid of them.




    David Wilkinson | Visual C++ MVP
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:34 AM
    Wednesday, September 17, 2008 9:54 AM
  • WCHAR szVolumeNameBuffer[10];
    DWORD dwVolumeSerialNumber;
    DWORD dwMaximumComponentLength;
    DWORD dwFileSystemFlags;
    WCHAR szFileSystemNameBuffer[12];
    GetVolumeInformation(L"C:\\", szVolumeNameBuffer, sizeof(szVolumeNameBuffer), &dwVolumeSerialNumber, &dwMaximumComponentLength, &dwFileSystemFlags, szFileSystemNameBuffer, sizeof(szFileSystemNameBuffer));
    this->textBox12->Text = dwVolumeSerialNumber.ToString();

    Ok, well it desplays a butch of numbers in the textbox. But i noticed that it is not my HardDrive serial #.
    Am not shure why it is doing this maby i did somthing wrong.
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:34 AM
    Wednesday, September 17, 2008 7:11 PM
  • Further to what ildjarn said, the _countof macro is useful for this.


    David Wilkinson | Visual C++ MVP
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:33 AM
    Wednesday, September 17, 2008 7:25 PM
  • It may work, but there are a couple of problems.

    1. You are still using sizeof on wchar_t strings. Use _countof() instead, or inroduce two const int's and use them for both the definition of the array sizes, and the sizes passed to GetVolumeInformation()

    2. You are mixing char strings, wchar_t strings, TCHAR strings  and System::String.

    The purpose of the TCHAR type is so you can write code that will compile in both ANSI and Unicode mode. But in modern code, especially mixed mode code, you never want to compile ANSI so there is not much point to this -- just use wchar_t consistently (you already have L"C:\\" which is a wchar_t string). And get rid of the char[20] array. You could use a wchar_t array and wsprintf, but why not use managed code to build the string directly?


    David Wilkinson | Visual C++ MVP
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:32 AM
    Thursday, September 18, 2008 10:57 AM

All replies


  • Have a look on the Following Link
    http://www.codeproject.com/KB/mcpp/DriveInfoEx.aspx

    And this link  also  http://www.devlib.net/getdiskserial.htm, it shows some example for getting info of your hard drive



    Thanx

    Rupesh Shukla
    • Edited by Pintu Shukla Monday, September 15, 2008 5:27 AM Link
    Monday, September 15, 2008 5:25 AM
  • yes i tryed thoes the other day and retried them today but i cant seam to get them to work right.
    Monday, September 15, 2008 8:51 PM
  • Stefanlg:

    You do not seem to have learned much from what I tried to teach you yesterday. Rupesh Shukla has given you what he believes to be the answer. You respond that you tried it but you cannot get it to work right. What is Rupesh supposed to do now?

    Describe what you did
    Describe what happened
    Describe what you expected to happen

    In any case, this question is not about the C++ language, so it is in the wrong forum.

    David Wilkinson | Visual C++ MVP
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:33 AM
    Monday, September 15, 2008 9:26 PM
  • Omg, I took the source from the link he sent me. I compliled the source. I got these errors.

    1>c:\users\k2killer\desktop\driveinfoex\driveinfoex\driveinfoex\UnmanagedCode.h(50) : error C2011: '_GETVERSIONINPARAMS' : 'struct' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2403) : see declaration of '_GETVERSIONINPARAMS'

    1>c:\users\k2killer\desktop\driveinfoex\driveinfoex\driveinfoex\UnmanagedCode.h(61) : error C2011: '_IDEREGS' : 'struct' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2426) : see declaration of '_IDEREGS'

    1>c:\users\k2killer\desktop\driveinfoex\driveinfoex\driveinfoex\UnmanagedCode.h(76) : error C2011: '_SENDCMDINPARAMS' : 'struct' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>c:\users\k2killer\desktop\driveinfoex\driveinfoex\driveinfoex\UnmanagedCode.h(94) : error C2011: '_DRIVERSTATUS' : 'struct' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2478) : see declaration of '_DRIVERSTATUS'

    1>c:\users\k2killer\desktop\driveinfoex\driveinfoex\driveinfoex\UnmanagedCode.h(105) : error C2011: '_SENDCMDOUTPARAMS' : 'struct' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2517) : see declaration of '_SENDCMDOUTPARAMS'

    1>.\UnmanagedCode.cpp(61) : error C2079: 'GetVersionParams' uses undefined struct '_GETVERSIONINPARAMS'

    1>.\UnmanagedCode.cpp(79) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(79) : error C2227: left of '->irDriveRegs' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(79) : error C2228: left of '.bCommandReg' must have class/struct/union

    1>.\UnmanagedCode.cpp(90) : error C2027: use of undefined type '_SENDCMDOUTPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2517) : see declaration of '_SENDCMDOUTPARAMS'

    1>.\UnmanagedCode.cpp(90) : error C2227: left of '->bBuffer' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(150) : error C2079: 'scip' uses undefined struct '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(166) : error C2664: 'DiskInfo::DoIDENTIFY' : cannot convert parameter 2 from 'int *' to 'PSENDCMDINPARAMS'

    1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    1>.\UnmanagedCode.cpp(171) : error C2027: use of undefined type '_SENDCMDOUTPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2517) : see declaration of '_SENDCMDOUTPARAMS'

    1>.\UnmanagedCode.cpp(171) : error C2227: left of '->bBuffer' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(210) : error C2011: '_STORAGE_QUERY_TYPE' : 'enum' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(641) : see declaration of '_STORAGE_QUERY_TYPE'

    1>.\UnmanagedCode.cpp(221) : error C2011: '_STORAGE_PROPERTY_ID' : 'enum' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(652) : see declaration of '_STORAGE_PROPERTY_ID'

    1>.\UnmanagedCode.cpp(231) : error C2011: '_STORAGE_PROPERTY_QUERY' : 'struct' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(667) : see declaration of '_STORAGE_PROPERTY_QUERY'

    1>.\UnmanagedCode.cpp(265) : error C2011: '_STORAGE_DEVICE_DESCRIPTOR' : 'struct' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(710) : see declaration of '_STORAGE_DEVICE_DESCRIPTOR'

    1>.\UnmanagedCode.cpp(440) : error C2079: 'query' uses undefined struct '_STORAGE_PROPERTY_QUERY'

    1>.\UnmanagedCode.cpp(445) : error C2039: 'PropertyId' : is not a member of 'System::Int32'

    1> c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::Int32'

    1>.\UnmanagedCode.cpp(446) : error C2039: 'QueryType' : is not a member of 'System::Int32'

    1> c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::Int32'

    1>.\UnmanagedCode.cpp(461) : error C2027: use of undefined type '_STORAGE_DEVICE_DESCRIPTOR'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(710) : see declaration of '_STORAGE_DEVICE_DESCRIPTOR'

    1>.\UnmanagedCode.cpp(461) : error C2227: left of '->SerialNumberOffset' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(507) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(507) : error C2227: left of '->cBufferSize' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(508) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(508) : error C2227: left of '->irDriveRegs' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(508) : error C2228: left of '.bFeaturesReg' must have class/struct/union

    1>.\UnmanagedCode.cpp(509) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(509) : error C2227: left of '->irDriveRegs' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(509) : error C2228: left of '.bSectorCountReg' must have class/struct/union

    1>.\UnmanagedCode.cpp(510) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(510) : error C2227: left of '->irDriveRegs' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(510) : error C2228: left of '.bSectorNumberReg' must have class/struct/union

    1>.\UnmanagedCode.cpp(511) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(511) : error C2227: left of '->irDriveRegs' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(511) : error C2228: left of '.bCylLowReg' must have class/struct/union

    1>.\UnmanagedCode.cpp(512) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(512) : error C2227: left of '->irDriveRegs' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(512) : error C2228: left of '.bCylHighReg' must have class/struct/union

    1>.\UnmanagedCode.cpp(515) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(515) : error C2227: left of '->irDriveRegs' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(515) : error C2228: left of '.bDriveHeadReg' must have class/struct/union

    1>.\UnmanagedCode.cpp(518) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(518) : error C2227: left of '->irDriveRegs' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(518) : error C2228: left of '.bCommandReg' must have class/struct/union

    1>.\UnmanagedCode.cpp(519) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(519) : error C2227: left of '->bDriveNumber' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(520) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(520) : error C2227: left of '->cBufferSize' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(704) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(704) : error C2227: left of '->irDriveRegs' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(704) : error C2228: left of '.bCommandReg' must have class/struct/union

    1>.\UnmanagedCode.cpp(705) : error C2027: use of undefined type '_SENDCMDINPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>.\UnmanagedCode.cpp(705) : error C2227: left of '->bDriveNumber' must point to class/struct/union/generic type

    1>.\UnmanagedCode.cpp(717) : error C2027: use of undefined type '_SENDCMDOUTPARAMS'

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2517) : see declaration of '_SENDCMDOUTPARAMS'

    1>.\UnmanagedCode.cpp(717) : error C2227: left of '->bBuffer' must point to class/struct/union/generic type

    1>DriveInfoEx.cpp

    1>c:\users\k2killer\desktop\driveinfoex\driveinfoex\driveinfoex\unmanagedcode.h(50) : error C2011: '_GETVERSIONINPARAMS' : 'struct' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2403) : see declaration of '_GETVERSIONINPARAMS'

    1>c:\users\k2killer\desktop\driveinfoex\driveinfoex\driveinfoex\unmanagedcode.h(61) : error C2011: '_IDEREGS' : 'struct' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2426) : see declaration of '_IDEREGS'

    1>c:\users\k2killer\desktop\driveinfoex\driveinfoex\driveinfoex\unmanagedcode.h(76) : error C2011: '_SENDCMDINPARAMS' : 'struct' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2462) : see declaration of '_SENDCMDINPARAMS'

    1>c:\users\k2killer\desktop\driveinfoex\driveinfoex\driveinfoex\unmanagedcode.h(94) : error C2011: '_DRIVERSTATUS' : 'struct' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2478) : see declaration of '_DRIVERSTATUS'

    1>c:\users\k2killer\desktop\driveinfoex\driveinfoex\driveinfoex\unmanagedcode.h(105) : error C2011: '_SENDCMDOUTPARAMS' : 'struct' type redefinition

    1> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(2517) : see declaration of '_SENDCMDOUTPARAMS'

    Monday, September 15, 2008 9:38 PM
  • Stefanlg:

    Well, all these errors are the same. There is no need to dump them all on us. Just look at the first one. The compiler says that the struct
    _GETVERSIONINPARAMS has been defined twice. And it tells you where those two places are. So why don't you try to figure out why this is happening?

    Only you have access to all this information.


    David Wilkinson | Visual C++ MVP
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:33 AM
    Monday, September 15, 2008 10:13 PM
  • Dude i had checked that codeguru article sample and it is working proper at my side . I hope you want some idea how to do that so why not read it carefully ,And try to understand how the things is going on .If still problem Let me know .

    Thanx 
    Rupesh Shukla
    Tuesday, September 16, 2008 8:25 AM
  • ok, weel puntu for somereason the code still doesn't work. but it did find this.

    Drive, Name : array[0..255] of Char;

    SerialNum, CompLength, Flags : DWord;

    this->textBox12->Text = GetVolumeInformation("C:\\", Name, 256, @SerialNum, CompLength, Flags, nil, 256);



    but i am getting

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(392) : error C2018: unknown character '0x40'

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(390) : error C2065: 'Drive' : undeclared identifier

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(390) : error C2143: syntax error : missing ';' before ':'

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(390) : error C2143: syntax error : missing ';' before ':'

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(391) : error C2065: 'SerialNum' : undeclared identifier

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(391) : error C2065: 'CompLength' : undeclared identifier

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(391) : error C2065: 'Flags' : undeclared identifier

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(391) : error C2143: syntax error : missing ';' before ':'

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(391) : error C2143: syntax error : missing ';' before ':'

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(392) : error C2065: 'SerialNum' : undeclared identifier

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(392) : error C2065: 'CompLength' : undeclared identifier

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(392) : error C2065: 'Flags' : undeclared identifier

    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(392) : error C2065: 'nil' : undeclared identifier

    Tuesday, September 16, 2008 6:39 PM
  • Erm.. Is that Pascal? Try C++ syntax...
    Tuesday, September 16, 2008 6:45 PM
  • Stefanlg:

    I hate to keep nagging you, but you are really not using the forums effectively. There is no reason to post code with glaring compiler errors; as ildjarn says, this example does not even look like C++.

    Either you are interested in solving your problems or you are not. If you are not, you should not be bothering the people in these forums. If you are, surely it has to be more efficient for you to make some reasonable attempt to solve your problem yourself. This particular issue of drive info you first raised two days ago, and you have not really made much progress, because very time you get stuck you post some poorly thought out question.

    Asking a question in the forums should be the last resort, not the first resort.






    David Wilkinson | Visual C++ MVP
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:34 AM
    Tuesday, September 16, 2008 9:40 PM
  •  ok, i think i got it now but i am having only one problem.

    WCHAR szVolumeNameBuffer[10];
    DWORD dwVolumeSerialNumber;
    DWORD dwMaximumComponentLength;
    DWORD dwFileSystemFlags;
    WCHAR szFileSystemNameBuffer[12];
    GetVolumeInformation("C:\\", (LPWSTR)szVolumeNameBuffer, 12, &dwVolumeSerialNumber, &dwMaximumComponentLength, &dwFileSystemFlags, (LPWSTR)szFileSystemNameBuffer, 10);

    for 10); it is telling me
    1>j:\hacks\visual studio 2008 - files\sys-info\sys-info\Form1.h(406) : error C2664: 'GetVolumeInformationW' : cannot convert parameter 1 from 'const char [4]' to 'LPCWSTR'

    • Edited by Stefanlg55 Wednesday, September 17, 2008 2:01 AM
    Wednesday, September 17, 2008 2:00 AM
  • Change "C:\\" to L"C:\\" (note the L prefix). Also, read this.
    Wednesday, September 17, 2008 3:30 AM
  • Thanks that worked. But it should be showing the Serial number in the texbox but it is only showing 1.
    If it is bool how would i change it so it will just show the serial.
    Wednesday, September 17, 2008 4:04 AM
  • Thanks that worked. But it should be showing the Serial number in the texbox but it is only showing 1.
    If it is bool how would i change it so it will just show the serial.
    Wednesday, September 17, 2008 4:04 AM
  • What does that mean .I think you had resolved your problem .Modification part you can do by yourself .It Just require Little bit effort from you . I am sure that you are able to do this .If again problem Please let me know but before that just give it a try by yourself.

    Thanx

    Rupesh Shukla
    Wednesday, September 17, 2008 4:52 AM
  • Stefanlg:

    Did you read the documentation on GetVolumeInformation? The BOOL (not bool) return value just indicates whether the function succeeded. The volume information is returned in the other parameters.

    By the way, you do not need the (LPWSTR) casts in your code, and you should get rid of them.




    David Wilkinson | Visual C++ MVP
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:34 AM
    Wednesday, September 17, 2008 9:54 AM
  • It's also worth noting that you're making szVolumeNameBuffer length 10 and szFileSystemNameBuffer length 12, but you're telling GetVolumeInformation the opposite. I.e., you're telling GetVolumeInformation that szVolumeNameBuffer is length 12 and szFileSystemNameBuffer is length 10. This is a nice recipe for stack corruption.
    Wednesday, September 17, 2008 6:30 PM
  • WCHAR szVolumeNameBuffer[10];
    DWORD dwVolumeSerialNumber;
    DWORD dwMaximumComponentLength;
    DWORD dwFileSystemFlags;
    WCHAR szFileSystemNameBuffer[12];
    GetVolumeInformation(L"C:\\", szVolumeNameBuffer, sizeof(szVolumeNameBuffer), &dwVolumeSerialNumber, &dwMaximumComponentLength, &dwFileSystemFlags, szFileSystemNameBuffer, sizeof(szFileSystemNameBuffer));
    this->textBox12->Text = dwVolumeSerialNumber.ToString();

    Ok, well it desplays a butch of numbers in the textbox. But i noticed that it is not my HardDrive serial #.
    Am not shure why it is doing this maby i did somthing wrong.
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:34 AM
    Wednesday, September 17, 2008 7:11 PM
  • sizeof is not going to do what you expect here. It's going to return the number of bytes each WCHAR[] takes up, whereas you want the number of characters. Note that each WCHAR is two bytes.
    Wednesday, September 17, 2008 7:15 PM
  • Hey you have Sample Code with you .Now you should concentrate on the code and flow of program.Do you want to write a fresh code for you if yes please let us know. Because almost 18 post over and still you had not solved your problem.

    Thanx

    Rupesh Shukla
    Wednesday, September 17, 2008 7:21 PM
  • Further to what ildjarn said, the _countof macro is useful for this.


    David Wilkinson | Visual C++ MVP
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:33 AM
    Wednesday, September 17, 2008 7:25 PM
  • Ok, i started over again and i managed to get it to work this time. If anyone wants the code here it is.

    DWORD serialNumber, maxComponentLength, fsFlags; TCHAR szFileSystem[12]; TCHAR szVolumeName[24];
    GetVolumeInformation(L
    "C:\\", szVolumeName, sizeof(szVolumeName), &serialNumber, &maxComponentLength, &fsFlags, szFileSystem, sizeof(szFileSystem));
    char Return[20]; sprintf(Return, "%04X-%04X", serialNumber >> 16, serialNumber & 0xFFFF);
    this->textBox12->Text = gcnew String(Return);

    Thursday, September 18, 2008 4:52 AM
  • It may work, but there are a couple of problems.

    1. You are still using sizeof on wchar_t strings. Use _countof() instead, or inroduce two const int's and use them for both the definition of the array sizes, and the sizes passed to GetVolumeInformation()

    2. You are mixing char strings, wchar_t strings, TCHAR strings  and System::String.

    The purpose of the TCHAR type is so you can write code that will compile in both ANSI and Unicode mode. But in modern code, especially mixed mode code, you never want to compile ANSI so there is not much point to this -- just use wchar_t consistently (you already have L"C:\\" which is a wchar_t string). And get rid of the char[20] array. You could use a wchar_t array and wsprintf, but why not use managed code to build the string directly?


    David Wilkinson | Visual C++ MVP
    • Marked as answer by Yan-Fei Wei Friday, September 19, 2008 8:32 AM
    Thursday, September 18, 2008 10:57 AM