• 相关软件
    >Gettype 创建者:webmaster 更新时间:2005-10-14 00:09

    将系统环境变量 %ERRORLEVEL% 设置为与指定的 Windows 操作系统相关的值。


    语法


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


    参数



    /s Computer
    指定远程计算机名称或 IP 地址(不能使用反斜杠)。默认值是本地计算机。此参数适用于在命令中指定的所有文件和文件夹。
    /u [Domain\]User
    使用特定用户帐户的权限运行脚本。该默认值是系统权限。
    /p [Password]
    指出 /u 参数中指定的用户帐户的密码。
    /role
    返回操作系统的角色。
    /sp
    返回已安装的最新 service pack。
    /ver
    返回版本信息。
    /minv
    只返回次版本。
    /majv
    只返回主版本。
    /type
    返回所安装操作系统的类型。
    /build
    返回所安装操作系统的内部版本号码。
    /?
    在命令提示符下显示帮助。


    注释



    • 在批处理文件中执行某些操作之前,管理员可以使用 gettype 检测混合环境中 Windows 软件的安装信息。有时,只在运行特定的 Windows 操作系统的客户端计算机或服务器上运行软件或脚本是非常必要的。
    • Gettype 可识别下列操作系统:
         

           
      • Windows XP Home Editionid=personal>
           
      • Windows XP Professionalid=pro>
           
      • Windows Server 2003 Standard Editionid=Server>
           
      • Windows Server 2003 Enterprise Editionid=AdvServer>
           
      • Windows Server 2003 Datacenter Editionid=Datacenter>
           
      • Windows Server 2003 Web Editionid=WebServer>

      •    

    • 与大多数命令行工具不同,gettype 成功执行后不返回 0。而是返回表明当前操作系统产品类型的代码。
         

      Gettype 查询href="HELP=glossary.hlp TOPIC=gls_registry">注册表中的安装类型并将错误值设置为下表中描述的值,以此来确定操作系统类型。


         
         
           
             
             
           
           
             
             
           
           
             
             
           
           
             
             
           
           
             
             
           
           
             
             
           
           
             
             
           
         
       
      ERRORLEVEL描述
      1Windows XP Home Editionid=personal>
      2Windows XP Professionalid=pro>
      3Windows Server 2003 Standard Editionid=Server>
      4Windows Server 2003 Enterprise Editionid=AdvServer>
      5Windows Server 2003 Datacenter Editionid=Datacenter>
      6Windows Server 2003 Web Editionid=WebServer>

         

      Gettype 查询href="HELP=glossary.hlp TOPIC=gls_registry">注册表中的安装类型并将错误值设置为下表中描述的值,以此来确定操作系统角色。


         
         
           
             
             
           
           
             
             
           
           
             
             
           
           
             
             
           
         
       
      ERRORLEVEL描述
      1域控制器
      2成员服务器
      3工作组

    • 发生错误事件时,gettype 返回 errorlevel 值 255。
    • 如果没有安装 service pack,则 ERRORLEVEL 为 0。如果安装了 service pack 1,则 ERRORLEVEL 为 1。如果安装了 service pack 2,则 ERRORLEVEL 为 2,依此类推。
    • 如果安装了 Windows XPid=windowsxp>,则主版本为 5 且将 ERRORLEVEL 解释为 5000。如果次版本为 1,则将 ERRORLEVEL 解释为 100。若要同时获取主版本和次版本,则将 ERRORLEVEL 解释为 5100。如果发生某个错误条件,则将 ERRORLEVEL 设置为 255。


    示例


    通过在批处理文件中使用 gettype,可以创建只在检测到特定的平台时才运行的脚本。例如,如果您正在运行 Windows NT,则下列批处理文件检测操作系统类型。如果您未运行 Windows NT,则它将退出脚本。



    @echo off
    REM 批处理文件以检测操作系统
    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 Windows Server 2003 Datacenter Edition.
    goto END

    :FOUR
    echo Windows Server 2003 Enterprise Edition.
    goto END

    :THREE
    echo Windows Server 2003 Standard Edition.
    goto END

    :TWO
    echo Windows XP Professional.
    goto END

    :ONE
    echo Windows XP Home Edition.
    goto END

    :END
    pause


    格式化图例




     
       
       
     
     
       
       
     
     
       
       
     
     
       
       
     
     
       
       
     
     
       
       
     
     
       
       
     

    格式含义
    斜体用户必须提供的信息
    粗体用户必须准确键入的要显示的元素
    省略号 (...)在命令行中可多次重复的参数
    中括号 ([])可选项
    大括号 ({});选项用竖线 (|) 分隔。例如:{even|odd}用户必须从选项集合中选择一个
    Courier 字体代码或程序输出
    相关文章
    本页查看次数: