📄 osinfo.c
字号:
*
* Returns: TRUE if an error occured.
*********************************************************************/
BOOL WinVerDetect (WORD *pwWindowsType,
WORD *pwWindowsMajor,
WORD *pwWindowsMinor,
WORD *pfDosShell)
{
WORD wWindowsType; /* Local copies of data */
WORD wWindowsMajor;
WORD wWindowsMinor;
BOOL fDosShell = FALSE; /* Defaults to FALSE */
_asm
{
; Check for Windows 3.1
mov ax,160Ah ; WIN31CHECK
int 2Fh ; check if running under win 3.1
or ax,ax
jnz Win30EnhModeCheck
; Windows 3.1 detected
mov wWindowsMajor,3 ; Set the version number
mov wWindowsMinor,10
; CX = 3 - Enhanced, CX = 2 - Standard, CX = 1 - Real.
cmp cx,1
jne Win31StdChk
mov wWindowsType, WIN_REAL_MODE
jmp WinDetectComplete
Win31StdChk:
cmp cx,2
jne Win31EnhChk
mov wWindowsType, WIN_STANDARD_MODE
jmp WinDetectComplete
Win31EnhChk:
cmp cx,3
jne Win31UnknownMode
mov wWindowsType, WIN_ENHANCED_MODE
jmp WinDetectComplete
Win31UnknownMode:
mov wWindowsType, WIN_UNKNOWN_MODE
jmp WinDetectComplete
; Check for 3.0 Enhanced mode
Win30EnhModeCheck:
mov ax,1600h ; WIN386CHECK
int 2Fh
test al,7Fh
jz Win286Check
; Windows 3.0 Enhanced Mode detected
mov wWindowsMajor,3 ; Set the version number
mov wWindowsMinor,0
; Set the mode
mov wWindowsType, WIN_ENHANCED_MODE
jmp WinDetectComplete
; Check for Windows/286
Win286Check:
mov ax,1700h ; WIN286CHECK
int 2Fh
cmp al,2h ; If /286 installed, ver = AL.AH
jnz WinOldApCheck ; /286 is always 2.x
; Windows/286 detected
xor bh,bh
mov bl,al
mov wWindowsMajor,bx
mov bl,ah
mov wWindowsMinor,bx
mov wWindowsType, WIN_286
jmp WinDetectComplete
; Check for Windows 3.0 WINOLDAP
WinOldApCheck:
mov ax,4680h ; IS_WINOLDAP_ACTIVE
int 2Fh
or ax,ax ; running under 3.0 derivative ?
jz DosShellCheck
; Windows is not running on this computer
jmp NotRunningUnderWin
; Check for DOS 5.0 DOSSHELL Task Switcher
DosShellCheck:
mov ax,4b02h ; detect switcher
push bx
push es
push di
xor bx,bx
mov di,bx
mov es,bx
int 2Fh
pop di
pop es
pop bx
or ax,ax
jnz RunningUnderWinStdReal30
; Running under DOS 5.0 task switcher
mov wWindowsMajor,0 ; Windows is not running
mov wWindowsMinor,0
mov wWindowsType, NO_WINDOWS
mov fDosShell, TRUE ; Set the flag for the DOSSHELL
jmp WinDetectComplete
RunningUnderWinStdReal30:
mov ax,1605h ; PMODE_START
int 2Fh
cmp cx,-1
jnz Running30RealOr386
; Windows 3.0 Standard Mode detected
mov ax,1606h ; PMODE_STOP
int 2Fh ; in case someone is accounting.
mov wWindowsMajor,3 ; Set the version number
mov wWindowsMinor,0
; Set the Windows mode
mov wWindowsType, WIN_STANDARD_MODE
jmp WinDetectComplete
Running30RealOr386:
mov ax,1606h ; PMODE_STOP
int 2Fh ; in case someone is accounting.
cmp al,1 ; WIN386CHECK again
jnz RunningUnderRealMode
cmp al,0FFh
jz RunningUnderWin386
RunningUnderRealMode:
mov wWindowsMajor,3 ; Set the version number
mov wWindowsMinor,0
; Set the Windows mode
mov wWindowsType, WIN_REAL_MODE
jmp WinDetectComplete
RunningUnderWin386:
mov wWindowsMajor,2
mov wWindowsMinor,0FFh
mov wWindowsType, WIN_386
jmp WinDetectComplete
NotRunningUnderWin:
mov wWindowsMajor,0 ; Windows is not running
mov wWindowsMinor,0
mov wWindowsType, NO_WINDOWS
WinDetectComplete:
}
/* Set the new-found values */
*pwWindowsType = wWindowsType;
*pwWindowsMajor = wWindowsMajor;
*pwWindowsMinor = wWindowsMinor;
*pfDosShell = fDosShell;
return (FALSE);
}
/*********************************************************************
* GetDosOemStrings - Gets the DOS OEM version string (the same as
* typing VER at the DOS prompt. This is
* accomplished by performing a COMMAND/C VER and
* re-routing the output to a file. The file is
* read, and the strings are stored in the pOsVer
* structure.
*
* pOsVer - Operating system version structure.
*
* Returns: TRUE if an error occured.
*********************************************************************/
BOOL GetDosOemStrings (OS_VERSION_STRUCT *pOsVer)
{
CHAR szTempPath[_MAX_PATH]; /* Stores path to temp directory */
BOOL fReturnValue; /* Return value from various functions */
/* Command to get the version */
CHAR szCommandVer[_MAX_PATH + 20];
CHAR chBuffer[80]; /* Local string buffer */
FILE *fileVer; /* file handle to read version file */
WORD i, u; /* Index variable, looping variable */
WORD wLastChar; /* Index to last character in path */
static CHAR FAR *fpszOemStrings = NULL;
/* Store the strings, so I only have */
/* to get them once */
struct find_t ft; /* Used to validate temp directory */
/* If I've already got the OEM strings, return them */
if (fpszOemStrings)
{
_fmemcpy (pOsVer->szOemVer, fpszOemStrings,
MAX_OEM_VER_STRINGS * MAX_OEM_VER);
}
else
{
/* Zero out the string */
memset (szTempPath, '\0', _MAX_PATH);
/* Get the TEMP or TMP path or current directory for the temp file */
strcpy (szTempPath, getenv (pszTemp));
if (szTempPath[0] != '\0')
{
/* Add "*.*" to the temp path */
strcpy (szCommandVer, szTempPath);
wLastChar = strlen (szCommandVer) - 1;
if (szCommandVer[wLastChar] != '\\')
strcat (szCommandVer, "\\");
strcat (szCommandVer, "*.*");
/* Check to see if the directory is valid */
fReturnValue = _dos_findfirst (szCommandVer, 0xFFFF, &ft);
if (fReturnValue != 0)
{
fTempPathInvalid = TRUE;
if (fCwIsReady)
{
strcpy (szTempPath, pszTemp);
strcat (szTempPath, "=");
strcat (szTempPath, getenv (pszTemp));
MessageBox (pszEnvironInvalid, szTempPath, NULL,
MB_OK | 0x8000);
}
szTempPath[0] = '\0';
}
}
if (szTempPath[0] == '\0')
{
strcpy (szTempPath, getenv (pszTmp));
if (szTempPath[0] != '\0')
{
/* Add "*.*" to the temp path */
strcpy (szCommandVer, szTempPath);
wLastChar = strlen (szCommandVer) - 1;
if (szCommandVer[wLastChar] != '\\')
strcat (szCommandVer, "\\");
strcat (szCommandVer, "*.*");
/* Check to see if the directory is valid */
fReturnValue = _dos_findfirst (szCommandVer, 0xFFFF, &ft);
if (fReturnValue != 0)
{
fTmpPathInvalid = TRUE;
if (fCwIsReady)
{
strcpy (szTempPath, pszTmp);
strcat (szTempPath, "=");
strcat (szTempPath, getenv (pszTmp));
MessageBox (pszEnvironInvalid, szTempPath, NULL,
MB_OK | 0x8000);
}
szTempPath[0] = '\0';
}
}
}
/* Current directory */
if (szTempPath[0] == '\0')
{
getcwd (szTempPath, _MAX_PATH - 1);
/* A: and B: are not allowed */
if (szTempPath[0] == '\0' ||
strnicmp (szTempPath, "A:", 2) == 0 ||
strnicmp (szTempPath, "B:", 2) == 0)
return (TRUE);
}
/* Add the filename */
wLastChar = strlen (szTempPath) - 1;
if (szTempPath[wLastChar] != '\\')
strcat (szTempPath, "\\");
strcat (szTempPath, "__MSD__.$$$");
/* Create the complete command string */
strcpy (szCommandVer, "VER > ");
strcat (szCommandVer, szTempPath);
fReturnValue = system (szCommandVer);
if (fReturnValue)
{
DeleteFile (szTempPath);
return (TRUE);
}
/* Open the file with the version */
fileVer = OpenFile (szTempPath, "rb", FALSE);
if (fileVer == NULL)
{
DeleteFile (szTempPath);
return (TRUE);
}
/* Read the DOS OEM version strings */
i = 0;
while (ReadLine (chBuffer, MAX_OEM_VER - 1, fileVer, FALSE) != EOF &&
i < MAX_OEM_VER_STRINGS)
{
if (chBuffer[0] != '\0')
{
strcpy (pOsVer->szOemVer[i++], chBuffer);
/* Word wrap the line if it's > 50 chars */
if (strlen (chBuffer) > 51)
{
/* Look back for a space */
for (u = 50; u > 0 && chBuffer[u] != ' '; --u)
;
/* Clear out the existing string */
pOsVer->szOemVer[i - 1][u] = '\0';
if (i < MAX_OEM_VER_STRINGS)
{
/* Copy the excess to the next string */
strcpy (pOsVer->szOemVer[i++], &chBuffer[++u]);
}
}
}
}
/* Close the temp file */
CloseFile (fileVer);
/* Delete the temp file */
DeleteFile (szTempPath);
/* Store the OEM Version strings for later use */
fpszOemStrings = _fmalloc (MAX_OEM_VER_STRINGS * MAX_OEM_VER);
if (fpszOemStrings)
_fmemcpy (fpszOemStrings, pOsVer->szOemVer,
MAX_OEM_VER_STRINGS * MAX_OEM_VER);
}
/* Check for DOS 4.01 */
if (pOsVer->wDosMajor == 4 && pOsVer->wDosMinor == 0)
{
for (i = 0; i < MAX_OEM_VER_STRINGS; ++i)
{
if (strstr (pOsVer->szOemVer[i], "4.01") != NULL)
pOsVer->wDosMinor = 1;
}
}
return (FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -