Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gaining information about hardware 1

Status
Not open for further replies.

SmileeTiger

Programmer
Mar 13, 2000
200
0
0
US
Hi,<br><br>I am attempting to gain information about the CD-ROM drive using some assembly code in VC++ the followinf code is what I have found on the MSDN site with some minor modifications.<br><br>#include &lt;windows.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;iostream.h&gt;<br><br>BOOL IsCDRomDrive (short nDrive);<br><br>BOOL IsCDRomDrive (short nDrive)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;BOOL bResult = FALSE;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Assume not a CD-ROM drive<br>&nbsp;&nbsp;&nbsp;__asm {<br> &nbsp;&nbsp;&nbsp;mov&nbsp;&nbsp;ax, 150Bh&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// MSCDEX CD-ROM Drive Check<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xor&nbsp;&nbsp;bx, bx<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mov&nbsp;&nbsp;cx, nDrive<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;&nbsp;2Fh<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmp&nbsp;&nbsp;bx, 0ADADh&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Check MSCDEX signature<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jne&nbsp;&nbsp;not_cd_drive<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;&nbsp;&nbsp;ax, ax&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Check the drive type<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jz&nbsp;&nbsp;&nbsp;not_cd_drive&nbsp;&nbsp;&nbsp;&nbsp;// 0 (zero) means not CD-ROM<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mov&nbsp;&nbsp;bResult, TRUE<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;not_cd_drive:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;return (bResult);<br>&nbsp;&nbsp;&nbsp;}<br><br>void main()<br>{<br>//I am just using '1' here as a sample drive<br><br>if (IsCDRomDrive(1))<br>{ <br> cout &lt;&lt; &quot;Yup&quot;;<br>}<br>cout &lt;&lt; &quot;end&quot;;<br>}<br><br><br>When I sun the code I get an access violation and I don't recieve the information I need. Does anyone have any ideas how to get this code working or can you suggest a differet approach to take?<br><br><br>Cory M Hicks<br><br>
 
Some background. My goal is to retrieve some information about the hardware in a users system (specifically the serial number on various parts of the hardware (ie HDD, BIOS, mother board)) using VC++ from what I learned from the MSDN site the best way to get this was using __asm in Visual C++. <br><br>If anyone could suggest another way to do this let me know.<br><br><br>Cory
 
Assuming you are doing this under 32bit Windows, use the Windows API function GetDriveType as described below:<br><br>The GetDriveType function determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or network drive. <br><br>UINT GetDriveType(<br><br>&nbsp;&nbsp;&nbsp;&nbsp;LPCTSTR lpRootPathName // address of root path <br>&nbsp;&nbsp;&nbsp;); <br>Parameters<br><br>lpRootPathName<br><br>Points to a null-terminated string that specifies the root directory of the disk to return information about. If lpRootPathName is NULL, the function uses the root of the current directory. <br><br>Return Values<br><br>The return value specifies the type of drive. It can be one of the following values: <br><br>Value Meaning<br>0 The drive type cannot be determined.<br>1 The root directory does not exist.<br>DRIVE_REMOVABLE The drive can be removed from the drive.<br>DRIVE_FIXED The disk cannot be removed from the drive.<br>DRIVE_REMOTE The drive is a remote (network) drive.<br>DRIVE_CDROM The drive is a CD-ROM drive.<br>DRIVE_RAMDISK The drive is a RAM disk.<br> <p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href= Page</a><br>
 
So something like this should be fine then?<br><br>I tested it on my system and it seems to be working fine<br><br>#include &quot;stdafx.h&quot;<br>#include &lt;windows.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;iostream.h&gt;<br><br>&nbsp;&nbsp;&nbsp;// Return values of GetDriveType().<br>#define EX_DRIVE_INVALID&nbsp;&nbsp;&nbsp;&nbsp;1<br>#define EX_DRIVE_FLOPPY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2<br>#define EX_DRIVE_FIXED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3<br>#define EX_DRIVE_REMOTE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4<br>#define EX_DRIVE_CDROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5<br>#define EX_DRIVE_REMOVABLE&nbsp;&nbsp;6<br>#define EX_DRIVE_RAMDISK&nbsp;&nbsp;&nbsp;&nbsp;7 <br><br><br><br>int main(int argc, char* argv[])<br>{<br> //The letter of the drive<br> char *drive;=&quot;a:&quot;;<br> UINT test;<br> <br> test=GetDriveType(drive);<br><br> //Determines what kind of drive it is.<br> switch (test)<br> {<br> case EX_DRIVE_FIXED:<br> cout &lt;&lt; &quot;EX_DRIVE_FIXED&quot;;<br> break;<br> case&nbsp;&nbsp;EX_DRIVE_INVALID:<br> cout &lt;&lt; &quot;EX_DRIVE_INVALID&quot;;<br> break;<br> case EX_DRIVE_REMOTE:<br> cout &lt;&lt; &quot;EX_DRIVE_REMOTE&quot;;<br> break;<br> case EX_DRIVE_REMOVABLE:<br> cout &lt;&lt; &quot;EX_DRIVE_REMOVABLE&quot;;<br> break;<br> case&nbsp;&nbsp;EX_DRIVE_CDROM:<br> cout &lt;&lt; &quot;EX_DRIVE_CDROM&quot;;<br> break;<br> case EX_DRIVE_FLOPPY:<br> cout &lt;&lt; &quot;EX_DRIVE_FLOPPY &quot;;<br> break;<br> case EX_DRIVE_RAMDISK:<br> cout &lt;&lt; &quot;EX_DRIVE_RAMDISK&quot;;<br> break;<br> default:<br> cout &lt;&lt; &quot;Nope doesn't work&quot;;<br> }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br>}<br><br><br>I am also trying to get the serial numbers from some of the hardware i a users system using the API calls win32_logicaldisk, win32_bios and win32_mainboard. There does not seem to be any information regarding these calls on the net. DO you have any idea where to look??<br><br><br>Cory M Hicks<br><br>
 
Looks ok to me, though DRIVE_REMOVABLE etc are already defined in winbase.h (On my compiler anyways). But your way will work also. As for the API calls win32_logicaldisk, win32_bios and win32_mainboard, I really don't know. My compiler's help files have no reference to these. Maybe if you post the above in the &quot;C++: Borland (Inprise)&quot; forum someone may know. I don't think there is a WinAPI forum, but then again I may have missed it. <p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href= Page</a><br>
 
SmileeTiger: <br>I was just surfing around today and stumbled accross the following page that might be of interest to you:<br><A HREF=" TARGET="_new"> <p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href= Page</a><br>
 
That is great stuff. Too bad GlobalDosAlloc only works in windows 3.1 otherwise this would do EXACTLY what I wanted.<br><br>Thanks anyways,<br><br>Cory
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top