home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / msdos / programm / 10743 < prev    next >
Encoding:
Text File  |  1992-11-18  |  3.6 KB  |  101 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!mcsun!sunic!aun.uninett.no!nuug!nntp.uio.no!hpv
  3. From: hpv@kelvin.uio.no (Hans Peter Verne)
  4. Subject: Detecting Windows, the solution !
  5. Message-ID: <HPV.92Nov18180936@kelvin.uio.no>
  6. Sender: news@ulrik.uio.no (Mr News)
  7. Nntp-Posting-Host: kelvin.uio.no
  8. Organization: University of Oslo, Norway
  9. Date: Wed, 18 Nov 1992 17:09:36 GMT
  10. Lines: 89
  11.  
  12.  
  13. < This is a borrowed account, short messages may be routed to Tormod >
  14.  
  15. Follow UP (from Tormod): Detecting Windows, and in which mode !
  16.  
  17. The section below are MY comments on all the suggestions I got...
  18. And finally a short program which works for me... I'm not saying
  19. that I'm doing it the correct way but it works. From all the responses
  20. I got it is clear to see that there is no 'proper' way. Couldn't 
  21. Microsoft have created ONE simple interrupt, which returns windows
  22. version, modifies AX on return and which mode we're in ?
  23.  
  24. I want to thank everyone who replied...( quite a few actually )
  25. ( To save netspace I'm not quoting, forgive me... ). 
  26. Please no flames. This may not be how you would do it !!
  27.  
  28. And so for the different propositions:
  29.  
  30. 'Peeking' the interrupt table is ambiguous, the table does not necessary 
  31. contain 00 in the offset if an interrupt handler is not installed. In fact
  32. it does not contain 0 at all but points to a default handler which just
  33. returns. All registers are generally the same as when we called it. 
  34.  
  35. Walking the MCB chain works, but requires the use of UNDOCUMENTED DOS
  36. which just happens to change between DOS versions.
  37.  
  38. 2F-1600 : Ambiguous test, there is no way to determine if the interrupt was
  39. handled correctly. If there is no 2F1600 handler installed AX will be
  40. 1600 on return. The test for enhanced mode when AL == 00 will
  41. always be true. Therefore in standard DOS, Windows is apparently 
  42. in enhanced mode ! I.e. before using this test we have to determine 
  43. if windows is running. ( That's what Microsoft does... )
  44.  
  45. 2F-160A : Found this one by tracing win.com. Works like this..
  46. int 2F   160A  ************* only under windows 3.1 *************
  47.   Return  
  48.         AX = 0
  49.         BX = 30A          isn't this the timestamp on Windows 3.0 files ?
  50.         CX = 003          Enhanced mode
  51.         CX = 002          Standard mode
  52.   Microsoft uses this in win.com in the following order:
  53.   2F-160A -> 2F-1600 -> 2F-4680
  54. An excellent interrupt since it sets AX to zero if a handler is present.
  55. Only present in 3.1 though.
  56.  
  57. 2F-4680 : also ambiguous if it's not established if Windows is running or 
  58. not, since if AX is non zero it's in enhanced mode ( same problem as 
  59. described in 2F1600 ). However if Windows is running, it's good. Since
  60. we will find out whether we're in enhanced mode or not. Drawback
  61. is that it's not officially documented. Microsoft uses it, though..
  62.  
  63. "windir" variable (lowercase) is not official either ( I read somewhere.. )
  64. but it works extremely well. It can be used to determine if Windows is 
  65. there at all. Then you can use 2F-4680.
  66.  
  67. /* and here is my choice...  Works under 3.0 and 3.1 */
  68.  
  69. #include <dos.h>
  70. #include <stdio.h>
  71. #include <stdlib.h>
  72. #include <string.h>
  73.  
  74. int main()   
  75. {
  76.     union REGS reg;
  77.     char *pEnvStr;
  78.  
  79.     if ((pEnvStr = (getenv("windir"))) != NULL)
  80.       printf("found 'windir' ( Windows is running )\n");
  81.     else
  82.     {
  83.       printf("Windows is not active\n");
  84.       return 0;
  85.     }
  86.     
  87.     /* this test can only be run after we've verified that windows is active */
  88.     reg.x.ax = 0x4680;  
  89.     int86(0x2f, ®, ®);
  90.     if ( reg.x.ax == 0 )   
  91.     {
  92.       printf("Real mode or standard is here....\n");
  93.       return 0;
  94.     }
  95.     printf("ENHANCED...\n");
  96.     return 0;
  97. }
  98.  
  99.  
  100.  
  101.