EditV32 1.5 - (C) 2006 by Bill Stewart (bstewart@iname.com)

Description:

EditV32 is intended for use in shell scripts (aka batch files). It provides the
ability to interactively edit environment variables. It is provided in two
versions: EditV32.exe is a Win32 console program that requires Windows NT 4.0
or later, and EditVar.exe is a real mode MS-DOS version that works in MS-DOS or
in Windows 9x/Me COMMAND.COM sessions.

EditV32 works by obtaining the contents of an environment variable (if it
exists) and presents it on the screen for editing. If you make changes to the
variable, EditV32 writes the variable back to the environment.

MS-DOS  The MS-DOS version locates the current program's parent environment
        (e.g., the environment block of the program that called it), and sets
        the variable in the parent environment. This procedure is specific to
        MS-DOS and does not work in Windows NT 4.0 or later.

Win32   The Win32 version obtains the process id of the parent process (i.e.,
        the program that started EditV32.exe), and uses Win32 API calls to set
        the variable in the environment for the parent process. The Win32 API
        calls it uses do not exist on Win9x/Me, so it will not execute in that
        environment. Windows NT 4.0 or later is required.

        Note that this behavior is markedly different from most other Win32
        environment modification tools on the NT 4.0 and later platform; most
        other tools make changes to the registry entries that the command shell
        (usually Cmd.exe) reads when it starts. With most of these other tools,
        if you make changes to the registry, the current Cmd.exe session won't
        see them, even if the tool broadcasts the change to Windows. EditV32
        doesn't work this way; it can add variables to the Cmd.exe session that
        started it, as if you used the Set command at the prompt.

Cmd.exe in Windows 2000 and later provide the Set /p command to allow user
input into an environment variable, but EditV32 provides a richer set of
features:

*   It allows you to edit a variable, not just set one.

*   It can limit the length of the typed variable.

*   It can provide masked input for simple password security.

*   It can limit typed input to numbers only.

*   It offers a timeout feature.

*   It can "escape" reserved shell characters in variables it creates (see
    below for more information).

*   It provides several useful exit codes.

*   The real mode MS-DOS version can be used on MS-DOS startup disks/CDs/DVDs.

For these reasons, EditV32 may be preferable to Set /p except in environments
where third-party executables are prohibited.

Usage:

EditV32 [-b] [-e] [-l len] [-m] [-n] [-o] [-p prompt] [-t n] [-u] var

Arguments:

-b          Place the cursor at the beginning of the input line (instead of the
            end).

-e          Do not insert shell escape characters before reserved shell
            characters in the environment variable's contents. (Win32 only)

-l len      Limits input to 'len' characters. In MS-DOS, the limit is 255
            characters; In Win32, the limit is 2047 characters.

-m          Masked input: Displays '*' for typed characters.

-n          Restricts input to numbers only (0-9).

-o          Starts the line editor in overtype mode instead of insert mode.

-p prompt   Specifies a prompt for the user. If it contains spaces or tabs,
            enclose it in quotes (").

-t n        Assume Enter was pressed if nothing typed within 'n' seconds.

-u          Forces entered characters to uppercase.

var         The environment variable's name (required). This name can be up to
            127 characters long. If the variable name contains spaces, enclose
            it in quotes.

Note that EditV32 has only one required command-line argument: The name of the
environment variable you want to edit. All other arguments are optional.

Note: You must place the environment variable name last on the command line
after all other arguments. All other arguments may appear in any order.

If the /? argument is present and is first on the command line, the program
will display a short usage message.

Exit Codes:

1       The command line contains an error
2       Nothing was typed on the input line
3       The environment variable's contents was not changed
4       The user pressed Ctrl-C to abort input
8       Insufficient space in environment to store variable (MS-DOS only)
126     Wrong operating system version or platform

Notes:

*   The Line Editor

    The Line editor uses the following keyboard commands:

    Keystroke           Effect
    ---------------------------------------------------------------------------
    Home                Beginning of input line
    End                 End of input line
    Left Arrow          Left one character
    Right Arrow         Right one character
    Ctrl-Left Arrow     Left one word
    Ctrl-Right Arrow    Right one word
    Ctrl-Home           Delete from cursor position to beginning of input line
    Ctrl-End            Delete from cursor position to the end of input line
    Esc                 Delete the entire input line
    Ctrl-U or Ctrl-Z    Undo (restore the line's original contents)
    Insert              Toggle insert mode
    Backspace           Delete character to left of cursor
    Delete              Delete current character
    Ctrl-C              Abort input

    There is no visual indication of insert or overtype mode. The line editor
    defaults to insert mode unless the -o argument exists on the command line.

*   MS-DOS Version Notes

    *   The MS-DOS version does not work (and won't run) on Windows NT 4.0 or
        later.

    *   You can't use any of the following characters in an environment
        variable: < > |

    *   An environment variable's contents can be up to 255 characters long.

    *   If there is not enough space in the environment block to store the
        variable, EditVar.exe will return an exit code of 8.

*   Win32 Version Notes

    *   The Win32 version does not work (and won't run) on Windows 9x/Me.

    *   The Win32 version "escapes" reserved shell characters in the variable
        it writes to the environment. The following characters are reserved
        shell characters:

        ( ) < > ^ & |

        If any of these characters exist in the variable, EditV32 will insert
        the shell escape character (^) before each reserved character. The
        variable will be truncated, if necessary, to accommodate the inserted
        escape character(s).

        Note that if you limit input to one character (-l 1) and you type a
        single reserved shell character, EditV32 will not save it to the
        environment and will instead return an exit code of 2.

        You can bypass this behavior with the -e argument.

    *   If EditV32.exe fails to set the environment variable in the target
        process, it will display the Win32 error message for the last Win32
        error it encountered, and its exit code will equal the last Win32
        error.

Examples:

1.  editv32 -p "Enter your user name: " NAME

    EditV32 will display the following prompt:

    Enter your user name:

    It will then place the contents of the NAME variable on the input line for
    editing.

2.  editv32 -b -l 1 -o -p "Are you sure? " -u YN

    If the variable YN exists, it will appear after the following prompt:

    Are you sure?

    EditV32 will place the cursor at the beginning of the input (-b), limit
    input to 1 character (-l 1), and input will be forced to uppercase (-u). In
    addition, the line editor will start in overtype mode (-o).
