Gibt es einen Befehl zum Abrufen einer Liste von cmd-Befehlen in Windows?

Wenn Sie auf einem Computer arbeiten, auf dem Windows offline (ohne Internetverbindung) ausgeführt wird, ist es möglich, über die Befehlszeile eine Liste der verfügbaren cmd-Befehle (einschließlich der Verwendung) abzurufen/zu generieren?

Author: Andrea, 2012-11-21

5 answers

Für eine Liste von Befehlen:

help

Und für Details zu einem bestimmten Befehl:

help <command>

Oder

<command> /?

Zum Beispiel:

help xcopy
xcopy /?
 20
Author: bummi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2012-11-21 12:26:55

Eine offizielle Liste finden Sie unter Microsoft Command-line reference AZ. Abgesehen davon...

Um Ihre Frage direkt zu beantworten, habe ich ein Skript entwickelt, das einfach alle .exe Dateien auflistet, die Sie ausführen können (da sie sich auf Ihrem PATH befinden). Standardmäßig werden nur diejenigen aufgelistet, die sich ebenfalls in %WINDIR% befinden (es sei denn, Sie führen es mit --all).

In einer früheren Iteration des Skripts habe ich jeden Befehl mit /? gestartet, was eine sehr schlechte Idee ist. Nicht jede Anwendung auf der PATH versteht diesen Parameter. Einige werden einfach gestartet und bleiben ausgeführt, anstatt Hilfe zu drucken. Das frisst also ziemlich schnell viele Ressourcen auf.

@SETLOCAL ENABLEEXTENSIONS 
@ECHO OFF

IF "%1"=="--all" (
    SET LIST_ALL=TRUE
)
CALL :printPath "%PATH%"
:printPath
FOR /F "tokens=1,* delims=;" %%A IN ("%~1") DO (
    IF EXIST "%%A" (
        PUSHD "%%A"
        FOR %%F IN (*.exe) DO (
            ECHO.%%~dnpfF | FINDSTR /C:"%WINDIR%" 1> NUL
            IF ERRORLEVEL 1 (
                IF "%LIST_ALL%"=="TRUE" ECHO.%%~dnpfF
            ) ELSE (
                ECHO.%%~dnpfF
            )
        )
        POPD
    ) ELSE (
        REM ECHO Skipping non-existent folder '%%A'
    )
    CALL :printPath "%%~B"
)
ENDLOCAL

Also, da. Dies gibt Ihnen eine Liste aller verfügbaren Befehle und deren Parameter. Wie Sie bereits erwarten können, ist es nicht so nützlich, wie man sich vorstellen könnte.

Hier ist, was wirklich wichtig!

Interessanter als die .exe Dateien auf Ihrem PATH sind die cmd.exe Built-Ins. Wie IF, FOR und SET. Ich habe keine vollständige Liste der integrierten Elemente, aber Sie können die meisten davon sehen, indem Sie cmd.exe /?:

DEL or ERASE
COLOR
CD or CHDIR
MD or MKDIR
PROMPT
PUSHD
POPD
SET
SETLOCAL
ENDLOCAL
IF
FOR
CALL
SHIFT
GOTO
START (also includes changes to external command invocation)
ASSOC
FTYPE

Zu diesem Zeitpunkt verweist die Hilfe jedoch auf Befehlserweiterungen, sodass die Liste möglicherweise unvollständig ist. Schauen wir uns einige Built-Ins genauer an:

FÜR /?

Die Dokumentation für den Befehl FOR listet alle Parameter auf, die Sie an FOR übergeben können. Dies ist das Go-to-Dienstprogramm, wenn Sie etwas im Zusammenhang mit schreiben möchten Schleifen.

Diese Dokumentation enthält auch die Erklärung für die verrückte "tilde-notation":

In addition, substitution of FOR variable references has been enhanced
You can now use the following optional syntax:

    %~I         - expands %I removing any surrounding quotes (")
    %~fI        - expands %I to a fully qualified path name
    %~dI        - expands %I to a drive letter only
    %~pI        - expands %I to a path only
    %~nI        - expands %I to a file name only
    %~xI        - expands %I to a file extension only
    %~sI        - expanded path contains short names only
    %~aI        - expands %I to file attributes of file
    %~tI        - expands %I to date/time of file
    %~zI        - expands %I to size of file
    %~$PATH:I   - searches the directories listed in the PATH
                   environment variable and expands %I to the
                   fully qualified name of the first one found.
                   If the environment variable name is not
                   defined or the file is not found by the
                   search, then this modifier expands to the
                   empty string

The modifiers can be combined to get compound results:

    %~dpI       - expands %I to a drive letter and path only
    %~nxI       - expands %I to a file name and extension only
    %~fsI       - expands %I to a full path name with short names only
    %~dp$PATH:I - searches the directories listed in the PATH
                   environment variable for %I and expands to the
                   drive letter and path of the first one found.
    %~ftzaI     - expands %I to a DIR like output line

IF /?

IF ist der Befehl zum Verzweigen von . Sie benötigen diese Seite, da sie die Vergleichsoperatoren auflistet:

If Command Extensions are enabled IF changes as follows:

    IF [/I] string1 compare-op string2 command
    IF CMDEXTVERSION number command
    IF DEFINED variable command

where compare-op may be one of:

    EQU - equal
    NEQ - not equal
    LSS - less than
    LEQ - less than or equal
    GTR - greater than
    GEQ - greater than or equal

SET /?

SET ermöglicht das Ausführen einer Vielzahl von Operationen für Variablen.

The /A switch specifies that the string to the right of the equal sign
is a numerical expression that is evaluated.  The expression evaluator
is pretty simple and supports the following operations, in decreasing
order of precedence:

    ()                  - grouping
    ! ~ -               - unary operators
    * / %               - arithmetic operators
    + -                 - arithmetic operators
    << >>               - logical shift
    &                   - bitwise and
    ^                   - bitwise exclusive or
    |                   - bitwise or
    = *= /= %= += -=    - assignment
      &= ^= |= <<= >>=
    ,                   - expression separator

Es ermöglicht auch die String-Manipulation durch die oben erwähnte "Tilde-Notation"

 15
Author: Der Hochstapler,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2012-11-21 20:15:43

Es ist ein Batch-Skript verfügbar unter dostips.com (CreateDosCommandIndex.bat), das eine HTML-Datei generiert, die die vollständige Liste der verfügbaren DOS-Befehle auf dem System enthält, zusammen mit ihrer jeweiligen Ausgabe, die über "commandname /?"

Ich melde es unten seit dostips.com scheint zu diesem Zeitpunkt DB-lastbezogene Probleme zu haben und ihre Website funktioniert zeitweise.

@ECHO OFF
REM.-- Prepare the Command Processor
SETLOCAL ENABLEEXTENSIONS

REM --
REM -- Copyright note
REM -- This script is provided as is.  No waranty is made, whatso ever.
REM -- You may use and modify the script as you like, but keep the version history with
REM -- recognition to http://www.dostips.com in it.
REM --

REM Version History:
REM         XX.XXX      YYYYMMDD Author Description
SET "version=01.000"  &:20051201 p.h.   initial version, origin http://www.dostips.com
SET "version=01.001"  &:20060122 p.h.   Fix missing exclamation marks in documentation (http://www.dostips.com)
SET "version=01.002"  &:20060218 p.h.   replaced TEXTAREA with PRE XMP (http://www.dostips.com)
SET "version=01.003"  &:20060218 p.h.   php embedding (http://www.dostips.com)
SET "version=01.004"  &:20060723 p.h.   fix page links for FireFox (http://www.dostips.com)
SET "version=01.005"  &:20061015 p.h.   invoke HELP via '"call" help', allows overriding help command with a help.bat file (http://www.dostips.com)
SET "version=01.006"  &:20061015 p.h.   cleanup progress indicator (http://www.dostips.com)
SET "version=01.007"  &:20080316 p.h.   use codepage 1252 to support european users (http://www.dostips.com)
SET "version=02.000"  &:20080316 p.h.   use FOR command to generate HTML, avoids most escape characters (http://www.dostips.com)
SET "version=02.000"  &:20100201 p.h.   now using css and xhtml
REM !! For a new version entry, copy the last entry down and modify Date, Author and Description
SET "version=%version: =%"

for /f "delims=: tokens=2" %%a in ('chcp') do set "restore_codepage=%%a"
chcp 1252>NUL

set "z=%~dpn0.htm"

rem echo.^<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"^> >"%z%"
echo.^<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"^> >"%z%"

set "title=DOS Command Index"
for /f "tokens=*" %%a in ('ver') do set "winver=%%a"

echo.Creating the header ...
for %%A in (
            "<html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'>"
            "<head>"
            "<style type='text/css'>"
            "  h1              {text-align:center;}"
            "  h2              {text-align:center;}"
            "  table.center    {margin-left: auto;margin-right: auto;}"
            "  td              {text-align:left;}"
            "  div.center      {text-align:center;}"
            "  div.sourcebatch {background: #DDDDDD;}"
            "  div.helptext    {background: #F8F8FF;}"
            "  div.top         {float: right;}"
            "</style>"
            "<title>%title%</title>"
            "<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1' />"
            "</head>"
            "<body bgcolor='#FFFFCC'>"
            "<font color='darkblue'>"
            "<h1>%title%</h1>"
            "<div class='center'>"
            "<table class='center' border='1' cellspacing='1' cellpadding='3'>"
            "    <tr><td>Windows Version</td><td>:</td><td>%winver%</td></tr>"
            "    <tr><td>Document Source</td><td>:</td><td>"
            "        <a href='http://www.dostips.com/'><b>http://www.dostips.com</a><br />"
            "        <a href='http://www.dostips.com/%~n0.php'><b>http://www.dostips.com/%~nx0.php</a>"
            "        </td></tr>"
            "    <tr><td>Created by</td><td>:</td><td><a href='http://www.dostips.com/%~nx0'>"
            "        <b>%~nx0</b></a><br /><a href='#%~n0'><b>Source Code below</b></a></td></tr>"
            "</table>"
            "</div>"
            "<br /><br />"
            "<table class='center'>"
            ) do echo.%%~A>>"%z%"

echo.Creating the index ...
set /a cnt=0
for /f "tokens=1,*" %%a in ('"help|findstr /v /b /c:" " /c:"For more""') do (
    for %%A in (
            "    <tr><td><a href='#%%a'>%%a</a></td><td>%%b</td></tr>"
            ) do echo.%%~A>>"%z%"
    set /a cnt+=1
)
for %%A in (
            "</table>"
            "<br /><br />"
            ) do echo.%%~A>>"%z%"

echo.Extracting HELP text ...
call:initProgress cnt
for /f %%a in ('"help|findstr /v /b /c:" " /c:"For more""') do (
    echo.Processing %%a
    for %%A in (
            "<div class='top'><a href='#'>TOP</a></div>"
            "<h2><a name='%%a'>%%a</a></h2>"
            "<div class='helptext'><pre><xmp>"
            ) do echo.%%~A>>"%z%"
    call help %%a >>"%z%" 2>&1
    echo ^</xmp^> >>"%z%"
    for %%A in (
            "</pre></div>"
            ) do echo.%%~A>>"%z%"
    call:tickProgress
)

echo.Injecting source script ...
for %%A in (
            ""
            "<br /><br />"
            "<div class='center'>"
            "<div class='top'><a href='#'>TOP</a></div>"
            "<a name='%~n0'><h2>DOS Batch Script Source that created this Document</h2></a>"
            "This %title% has been created automatically by the following DOS batch script:"
            "<br /><br />"
            "</div>"
            "<div class='sourcebatch'><pre><xmp>"
            ) do echo.%%~A>>"%z%"
type "%~f0" >>"%z%"

echo.Creating the footer ...
echo ^</xmp^> >>"%z%"
for %%A in (
            "</pre></div>"
            ""
            "</font>"
            "</body>"
            "</html>"
            ) do echo.%%~A>>"%z%"


chcp %restore_codepage%>NUL
explorer "%z%"

:SKIP
REM.-- End of application
FOR /l %%a in (5,-1,1) do (TITLE %title% -- closing in %%as&ping -n 2 -w 1 127.0.0.1>NUL)
TITLE Press any key to close the application&ECHO.&GOTO:EOF


::-----------------------------------------------------------
::helper functions follow below here
::-----------------------------------------------------------


:initProgress -- initialize an internal progress counter and display the progress in percent
::            -- %~1: in  - progress counter maximum, equal to 100 percent
::            -- %~2: in  - title string formatter, default is '[P] completed.'
set /a "ProgressCnt=-1"
set /a "ProgressMax=%~1"

set "ProgressFormat=%~2"
if "%ProgressFormat%"=="" set "ProgressFormat=[PPPP]"
set "ProgressFormat=%ProgressFormat:[PPPP]=[P] completed.%"
call :tickProgress
GOTO:EOF


:tickProgress -- display the next progress tick
set /a "ProgressCnt+=1"
SETLOCAL
set /a "per=100*ProgressCnt/ProgressMax"
set "per=%per%%%"
call title %%ProgressFormat:[P]=%per%%%
GOTO:EOF
 6
Author: adriano72,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2012-11-26 22:34:02

Es ist nicht genau das, was Sie nach einer Offline-Lösung suchen (Sie benötigen eine Internetverbindung, um die Webseite zu öffnen), sondern ein sehr nützliches Tool und eine Referenz für cmd-Befehle:

Ein AZ-Index der Windows CMD-Befehlszeile.

 3
Author: Diogo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2012-11-21 11:52:45

Ich weiß, dass es nicht genau das ist, wonach Sie fragen, aber Sie möchten möglicherweise Powershell anstelle der Eingabeaufforderung lernen. Microsoft versucht, die Eingabeaufforderung für Powershell auslaufen zu lassen, so wäre es eine gute Fähigkeit zu lernen.

Wenn Sie in Powershell sind der Befehl Get-Command listet alle Befehle auf, die derzeit von allen geladenen Modulen ausgeführt werden können. Es wird eine Ausgabe erzeugt, die wie folgt aussieht:

CommandType     Name                            Definition
-----------     ----                            ----------
Cmdlet          Add-Content                     Add-Content [-Path] <String[...
Cmdlet          Add-History                     Add-History [[-InputObject] ...
Cmdlet          Add-Member                      Add-Member [-MemberType] <PS...
Cmdlet          Add-PSSnapin                    Add-PSSnapin [-Name] <String...
Cmdlet          Clear-Content                   Clear-Content [-Path] <Strin...
 3
Author: Scott Chamberlain,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2012-11-21 23:28:56