gettype
Syntax
Parameters
Remarks
- Administrators can use gettype to detect Windows software installations in a mixed environment before performing some action in a batch file. Sometimes it is necessary to run software or scripts only on client computers or servers that are running a specific Windows operating system.
-
Gettype recognizes the following operating systems:
- Windows XP Home Edition
- Windows XP Professional
- Windows Server 2003, Standard Edition
- Windows Server 2003, Enterprise Edition
- Windows Server 2003, Datacenter Edition
- Windows Server 2003, Web Edition
-
Unlike most command-line tools, gettype does not return 0 for successful completion. Instead, it returns a code that specifies the product type of the current operating system.
Gettype determines the operating system type by querying the registry for the installation type and then setting the error value as described in the following table.
ERRORLEVEL Description 1 Windows XP Home Edition 2 Windows XP Professional 3 Windows Server 2003, Standard Edition 4 Windows Server 2003, Enterprise Edition 5 Windows Server 2003, Datacenter Edition 6 Windows Server 2003, Web Edition Gettype determines the operating system role by querying the registry for the installation type and then setting the error value as described in the following table.
ERRORLEVEL Description 1 Domain controller 2 Member server 3 Workgroup - In the event of an error, gettype returns an errorlevel of 255.
- If no service pack is installed, the ERRORLEVEL is 0. If service pack 1 is installed, the ERRORLEVEL is 1. If service pack 2 is installed, the ERRORLEVEL is 2, and so on.
- If Windows XP is installed, the major version is 5 and the ERRORLEVEL is interpreted as 5000. If the minor version is 1, the ERRORLEVEL is interpreted as 100. To get both major and minor versions together, the ERRORLEVEL is interpreted as 5100. If an error condition occurs, the ERRORLEVEL is set to 255.
Examples
@echo off REM Batch file to detect operating system REM ---------------------------------- if Windows_NT == %OS% goto WINNT echo You are NOT running Windows NT (Windows 95/98
perhaps?) goto END :WINNT gettype.exe if errorlevel=255 goto FILENOTFOUND echo You are running Windows NT. echo More Specifically: echo. if ERRORLEVEL=5 goto FIVE if ERRORLEVEL=4 goto FOUR if ERRORLEVEL=3 goto THREE if ERRORLEVEL=2 goto TWO if ERRORLEVEL=1 goto ONE :FILENOTFOUND echo. echo Gettype not found. echo. goto END :FIVE echo . goto END :FOUR echo . goto END :THREE echo . goto END :TWO echo . goto END :ONE echo . goto END :END pause
Formatting legend
Format | Meaning |
Italic | Information that the user must supply |
Bold | Elements that the user must type exactly as shown |
Ellipsis (...) | Parameter that can be repeated several times in a command line |
Between brackets ([]) | Optional items |
Between braces ({}); choices separated by pipe (|). Example: {even|odd} | Set of choices from which the user must choose only one |
Courier font | Code or program output |