Share via


Gettype

Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2

Gettype

Sets the system environment variable %ERRORLEVEL% to the value associated with the specified Windows operating system.

Syntax

gettype [/s Computer [/u [Domain**\]User [/p** [Password]]]] {/role | /sp | /ver | /minv | /majv | /type | /build}

Parameters
  • /s Computer
    Specifies the name or IP address of a remote computer (do not use backslashes). The default is the local computer. This parameter applies to all files and folders specified in the command.
  • /u [Domain\]User
    Runs the script with the permissions of the specified user account. The default is system permissions.
  • /p [Password]
    Specifies the password of the user account that is specified in the /u parameter.
  • /role
    Returns the role of the operating system.
  • /sp
    Returns the latest service pack installed.
  • /ver
    Returns version information.
  • /minv
    Returns only minor version.
  • /majv
    Returns only major version.
  • /type
    Returns the type of operating system that is installed.
  • /build
    Returns the build number of the operating system that is installed.
  • /?
    Displays help at the command prompt.
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

By using gettype within a batch file, you can create scripts that run only if a specific platform is detected. For example, the following batch file detects the operating system type if you are running Windows NT. It exits the script if you are not running Windows NT.

@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

See Also

Concepts

Command-line reference A-Z
Command shell overview