Get substring from Computer Name in DOS prompt
Results 1 to 2 of 2

Thread: Get substring from Computer Name in DOS prompt

  1. #1
    Join Date
    Sep 2003
    Posts
    2

    Get substring from Computer Name in DOS prompt

    Hi all,

    Beside for the path problem i would also like to ask if there is any DOS command which can retrieve the substring from the computername. E.g. my computer name is ABC123 and I would like to get the first 3 chars (ABC) for further process. How can I achieve this? Thanks for help.

    Best Regards,
    K.H.

  2. #2
    Join Date
    Feb 2000
    Location
    26.03°N 80.14°W
    Posts
    9,410
    For example:
    Code:
    @echo off
    :GetAbrv.bat - Type "getabrv /?" (without the quotes) for instructions.
     if (%1)==(?) goto Syntax
     if (%1)==(/?) goto Syntax
     goto Begin
    :Syntax
     echo.
     echo     Name: GetAbrv.bat
     echo.
     echo  Purpose: Takes the first three characters of an environment variable
     echo           named "computername" and puts them in an environment variable
     echo           named "computerabrv".
     echo.
     echo   Syntax: GetAbrv [/?]
     echo.
     echo Requires: 1) MS-DOS 5.00-6.22 or Windows 95/98/Me,
     echo.
     echo           2) an existing environment variable named "computername"
     echo              containing at least three characters,
     echo.
     echo           3) the program CHOICE.EXE (anywhere in the PATH),
     echo.
     echo           4) and at least 17 bytes of free space in the environment
     echo              to hold the new environment variable "computerabrv".
     echo.
     goto End
    :Begin
     if (%computername%)==() goto Error
     echo;;|choice/c:;%computername%; "set computerabrv=">~.bat
     call ~.bat
     echo set computerabrv=%%2%%3%%4>~.bat
     call ~ %computerabrv%
    :Display
     echo computername=%computername%
     echo computerabrv=%computerabrv%
    :Cleanup
     del ~.bat
     set cmdline=
     goto End
    :Error
     echo.
     echo    Error: Environment variable "computername" does not exist.
     goto Syntax
    :End
    Vernon Frazee, Microsoft MVP (Windows - Shell/User)

    Defenses Up!
    Tip: When prompted for a password, give an incorrect one first. A phishing site will accept it; a legitimate one won't.


    Inside Spyware: A Guide to Finding, Removing and Preventing Online Pests


    If you don't keep up with security fixes, your computer|network won't be yours for long.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •