Solved

Please help me

Posted on 1998-10-01
1
184 Views
Last Modified: 2010-04-01
I would like to find the media id of a compact disc
anyone can help???
0
Comment
Question by:Tonyleung
1 Comment
 
LVL 1

Accepted Solution

by:
roaknog earned 10 total points
ID: 1174254
#define VWIN32_DIOC_DOS_IOCTL 1

#include <windows.h>
#include <fstream.h>//for ofstream

//DECLARE SOME VARIABLES
      UINT nDrive = 4; //for cd drive d
      HANDLE hDevice;
      BOOL fResult;
      DWORD cb;
      char hexarray[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
      DWORD hfst, hscd, htrd, hfth, lfst, lscd, ltrd, lfth;

      typedef struct _midSN {
            WORD SNHighPart;
            WORD SNLowPart;
      } midSN;


      typedef struct _MID
      {
            WORD midInfoLevel;
            midSN midSerialNum;
            BYTE midVolLabel[11];
            BYTE midFileSysType[8];
      } MID, *PMID;

      MID mid;
      PMID pmid = &mid;

      typedef struct _DEVICEIOCTL_REGISTETRS
      {
            DWORD reg_EBX;
            DWORD reg_EDX;
            DWORD reg_ECX;
            DWORD reg_EAX;
            DWORD reg_EDI;
            DWORD reg_ESI;
            DWORD reg_Flags;
      } DEVIOCTL_REGISTERS, *PDEVIOCTL_REGISTERS;


void main()
      {
      DEVIOCTL_REGISTERS roakreg;
      PDEVIOCTL_REGISTERS preg = &roakreg;
      roakreg.reg_EAX = 0x440D;
      roakreg.reg_EBX = nDrive;
      roakreg.reg_ECX = 0x866;
      roakreg.reg_EDX = (DWORD)pmid;
      roakreg.reg_Flags = 0x8000;


// GET HANDLE
      hDevice = CreateFile("\\\\.\\vwin32",
            0,
            0,
            NULL,
            0,
            FILE_FLAG_DELETE_ON_CLOSE,
            NULL);

      fResult = DeviceIoControl(hDevice,
            VWIN32_DIOC_DOS_IOCTL,
            &roakreg,
            sizeof(roakreg),
            &roakreg,
            sizeof(roakreg),
            &cb,
            0);

//CLOSE HANDLE
      CloseHandle(hDevice);

//convert serial number to hex
      hfst = mid.midSerialNum.SNHighPart/4096;
      hscd = (mid.midSerialNum.SNHighPart-(hfst*4096))/256;
      htrd = (mid.midSerialNum.SNHighPart-(hfst*4096)-(hscd*256))/16;
      hfth = (mid.midSerialNum.SNHighPart-(hfst*4096)-(hscd*256)-(htrd*16));
      lfst = mid.midSerialNum.SNLowPart/4096;
      lscd = (mid.midSerialNum.SNLowPart-(lfst*4096))/256;
      ltrd = (mid.midSerialNum.SNLowPart-(lfst*4096)-(lscd*256))/16;
      lfth = (mid.midSerialNum.SNLowPart-(lfst*4096)-(lscd*256)-(ltrd*16));

//OUTPUT
      ofstream q("c:\\temp\\dioc.doc");
      q << "cb = " << cb << 
            ".\vhDevice = " << hDevice << 
            ".\v(HANDLE)INVALID_HANDLE_VALUE = " << (HANDLE)INVALID_HANDLE_VALUE << 
            ".\vfResult = " << fResult << 
            ".\vVWIN32_DIOC_DOS_IOCTL = " << VWIN32_DIOC_DOS_IOCTL <<
            ".\vnDrive = " << nDrive <<
            ".\vmid.midInfoLevel = " << mid.midInfoLevel <<
            ".\vWORD mid.midSerialNum.SNHighPart = " << mid.midSerialNum.SNHighPart <<
            ".\vWORD mid.midSerialNum.SNLowPart = " << mid.midSerialNum.SNLowPart <<
            ".\v&mid.midSerialNum.SNHighPart = " << &mid.midSerialNum.SNHighPart <<
            ".\v&mid.midSerialNum.SNLowPart = " << &mid.midSerialNum.SNLowPart <<
            ".\vhexadecimal mid.midSerialNum.SNHighPart = " << hexarray[hfst] << hexarray[hscd] << hexarray[htrd] << hexarray[hfth] <<
            ".\vhexadecimal mid.midSerialNum.SNLowPart = " << hexarray[lfst] << hexarray[lscd] << hexarray[ltrd] << hexarray[lfth] <<
            ".\vThe Serial Number is: " << hexarray[lfst] << hexarray[lscd] << hexarray[ltrd] << hexarray[lfth] << "-" << hexarray[hfst] << hexarray[hscd] << hexarray[htrd] << hexarray[hfth] <<
            ".\vmid.midVolLabel = " << mid.midVolLabel <<
            ".\vmid.midFileSysType = " << mid.midFileSysType <<
            ".\vmid->pmidInfoLevel = " << pmid->midInfoLevel <<
            ".\vmid->pmidVolLabel = " << pmid->midVolLabel <<
            ".\vmid->pmidFileSysType = " << pmid->midFileSysType <<
            ".\v(DWORD) pmid = " << (DWORD)pmid <<
            ".\vroakreg.reg_EDX = (DWORD) pmid = " << roakreg.reg_EDX  <<
            ".\vroakreg.reg_EBX = nDrive = " << roakreg.reg_EBX <<
            ".\vroakreg.reg_ECX = 0x866 = " << roakreg.reg_ECX <<
            ".\vroakreg.reg_Flags = 0x8000 = " << roakreg.reg_Flags <<
            ".\vroakreg.reg_EAX = " << roakreg.reg_EAX <<
            ".\v";

      cout << "\n     This program gets the media id of a cd at drive D:\\!\n\n     Function 440Dh of interrupt 21h is used!\n\n     The information is put into file c:\\temp\\dioc.doc!\n\n     This is not to be confused with the media in the FAT!\n\n     To get the media you could use function 1h of interrupt 25\n\n     with a boot structure, or offset 15h of a buffer!\n\n     (C) 1998 Inniea Publishing Company ROAK NOG!\n\n     ";
}
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question