cmdcmd

啟動命令直譯器的新實例,Cmd.exe。Starts a new instance of the command interpreter, Cmd.exe. 如果使用時不含參數, cmd 會顯示作業系統的版本和著作權資訊。If used without parameters, cmd displays the version and copyright information of the operating system.

語法Syntax

cmd [/c|/k] [/s] [/q] [/d] [/a|/u] [/t:{<b><f> | <f>}] [/e:{on | off}] [/f:{on | off}] [/v:{on | off}] [<string>]

參數Parameters

參數Parameter 描述Description
/C/c 執行 字串 所指定的命令,然後停止。Carries out the command specified by string and then stops.
/k/k 執行 字串 所指定的命令,並繼續進行。Carries out the command specified by string and continues.
/s/s /c/k之後修改字串的處理方式。Modifies the treatment of string after /c or /k.
/q/q 關閉回應。Turns the echo off.
/d/d 停用自動執行命令。Disables execution of AutoRun commands.
/a/a 將內部命令輸出格式化為管道或檔案,做為美國國家標準局 (ANSI) 。Formats internal command output to a pipe or a file as American National Standards Institute (ANSI).
/U/u 將內部命令輸出格式化為管線,或將檔案格式化為 Unicode。Formats internal command output to a pipe or a file as Unicode.
/t: {<b><f>/t:{<b><f> <f>}<f>} 設定背景 (b) 和前景 (f) 色彩。Sets the background (b) and foreground (f) colors.
/e:開啟/e:on 啟用命令延伸模組。Enables command extensions.
/e: off/e:off 停用命令延伸模組。Disables commands extensions.
/f:開啟/f:on 啟用檔案和目錄名稱的完成。Enables file and directory name completion.
/f: off/f:off 停用檔案和目錄名稱自動完成。Disables file and directory name completion.
/v:開啟/v:on 啟用延遲的環境變數擴充。Enables delayed environment variable expansion.
/v: off/v:off 停用延遲的環境變數擴充。Disables delayed environment variable expansion.
<string> 指定您想要執行的命令。Specifies the command you want to carry out.
/?/? 在命令提示字元顯示說明。Displays help at the command prompt.

下表列出您可以用來做為和值的有效十六進位數位 <b> <f>The following table lists valid hexadecimal digits that you can use as the values for <b> and <f>:

Value ColorColor
00 黑色Black
11 藍色Blue
22 綠色Green
33 AquaAqua
44 紅色Red
55 紫色Purple
66 黃色Yellow
77 白色White
88 灰色Gray
99 淺藍色Light blue
aa 淺綠Light green
bb 淺綠色Light aqua
cc 淺紅色Light red
dd 淺紫色Light purple
ee 淺黃色Light yellow
ff 亮白色Bright white

備註Remarks

  • 若要使用多個命令 <string> ,請使用命令分隔符號分隔它們, && 並將其括在引號中。To use multiple commands for <string>, separate them by the command separator && and enclose them in quotation marks. 例如:For example:

    "<command1>&&<command2>&&<command3>"
    
  • 如果您指定 /c/k,則只有在符合下列所有條件時,才會保留 cmd 進程、 字串的其餘部分和引號:If you specify /c or /k, cmd processes, the remainder of string, and the quotation marks are preserved only if all of the following conditions are met:

    • 您也不能使用 /sYou don't also use /s.

    • 您只能使用一組引號。You use exactly one set of quotation marks.

    • 您不會在引號內使用任何特殊字元 (例如: & < > ( ) @ ^ |) 。You don't use any special characters within the quotation marks (for example: & < > ( ) @ ^ | ).

    • 您可以使用引號內的一或多個空白字元。You use one or more white-space characters within the quotation marks.

    • 引號內的 字串 是可執行檔的名稱。The string within quotation marks is the name of an executable file.

    如果不符合上述條件,則會藉由檢查第一個字元來處理 字串 ,以確認它是否為左引號。If the previous conditions aren't met, string is processed by examining the first character to verify whether it is an opening quotation mark. 如果第一個字元是左雙引號,則會將它與右引號一起移除。If the first character is an opening quotation mark, it is stripped along with the closing quotation mark. 在右引號之後的任何文字都會保留下來。Any text following the closing quotation marks is preserved.

  • 如果您未在字串中指定 /d ,Cmd.exe 會尋找下列登錄子機碼:If you don't specify /d in string, Cmd.exe looks for the following registry subkeys:

    • HKEY_LOCAL_MACHINE \Software\Microsoft\Command Processor\AutoRun\ REG_SZHKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun\REG_SZ

    • HKEY_CURRENT_USER \Software\Microsoft\Command Processor\AutoRun\ REG_EXPAND_SZHKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun\REG_EXPAND_SZ

    如果有一個或兩個登錄子機碼,則會在所有其他變數之前執行。If one or both registry subkeys are present, they're executed before all other variables.

    警告

    不正確地編輯登錄可能會對系統造成嚴重的損害。Incorrectly editing the registry may severely damage your system. 變更登錄之前,您應該先備份電腦所有的重要資料。Before making changes to the registry, you should back up any valued data on the computer.

  • 您可以使用 /e: off來停用特定進程的命令延伸。You can disable command extensions for a particular process by using /e:off. 您可以設定下列REG_DWORD值,以啟用或停用電腦或使用者會話上所有命令行選項的延伸模組:You can enable or disable extensions for all cmd command-line options on a computer or user session by setting the following REG_DWORD values:

    • HKEY_LOCAL_MACHINE \Software\Microsoft\Command Processor\EnableExtensions\ REG_DWORDHKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\EnableExtensions\REG_DWORD

    • HKEY_CURRENT_USER \Software\Microsoft\Command Processor\EnableExtensions\ REG_DWORDHKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions\REG_DWORD

    使用) ,將 REG_DWORD 值設定為 0 × 1 (啟用) 或 0 × 0 (停用 Regedit.exe。Set the REG_DWORD value to either 0×1 (enabled) or 0×0 (disabled) in the registry by using Regedit.exe. 使用者指定的設定優先于電腦設定,而命令列選項優先于登錄設定。User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings.

    警告

    不正確地編輯登錄可能會對系統造成嚴重的損害。Incorrectly editing the registry may severely damage your system. 變更登錄之前,您應該先備份電腦所有的重要資料。Before making changes to the registry, you should back up any valued data on the computer.

    當您啟用命令延伸模組時,會影響下列命令:When you enable command extensions, the following commands are affected:

    • assocassoc

    • callcall

    • **chdir (cd) **chdir (cd)

    • colorcolor

    • **del (清除) **del (erase)

    • endlocalendlocal

    • forfor

    • ftypeftype

    • gotogoto

    • ifif

    • **mkdir (md) **mkdir (md)

    • popdpopd

    • promptprompt

    • pushdpushd

    • setset

    • setlocalsetlocal

    • shiftshift

    • 啟動 (也包含外部命令進程的變更) start (also includes changes to external command processes)

  • 如果您啟用延遲的環境變數擴充,您可以在執行時間使用驚嘆號字元來取代環境變數的值。If you enable delayed environment variable expansion, you can use the exclamation point character to substitute the value of an environment variable at run time.

  • 檔案和目錄名稱完成預設不會啟用。File and directory name completion is not enabled by default. 您可以使用 /f:{onoff} 來啟用或停用cmd命令之特定進程的檔案名稱完成 | ** **。You can enable or disable file name completion for a particular process of the cmd command with /f:{on | off}. 您可以藉由設定下列REG_DWORD值,啟用或停用電腦上cmd命令的所有進程或使用者登入會話的檔案和目錄名稱完成:You can enable or disable file and directory name completion for all processes of the cmd command on a computer or for a user logon session by setting the following REG_DWORD values:

    • HKEY_LOCAL_MACHINE \Software\Microsoft\Command Processor\CompletionChar\ REG_DWORDHKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\CompletionChar\REG_DWORD

    • HKEY_LOCAL_MACHINE \Software\Microsoft\Command Processor\PathCompletionChar\ REG_DWORDHKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\PathCompletionChar\REG_DWORD

    • HKEY_CURRENT_USER \Software\Microsoft\Command Processor\CompletionChar\ REG_DWORDHKEY_CURRENT_USER\Software\Microsoft\Command Processor\CompletionChar\REG_DWORD

    • HKEY_CURRENT_USER \Software\Microsoft\Command Processor\PathCompletionChar\ REG_DWORDHKEY_CURRENT_USER\Software\Microsoft\Command Processor\PathCompletionChar\REG_DWORD

    若要設定 REG_DWORD 值,請執行 Regedit.exe,並針對特定函式使用控制字元的十六進位值 (例如, 0 × 9 是 TAB,而 0 × 08 是倒退鍵) 。To set the REG_DWORD value, run Regedit.exe and use the hexadecimal value of a control character for a particular function (for example, 0×9 is TAB and 0×08 is BACKSPACE). 使用者指定的設定優先于電腦設定,而命令列選項優先于登錄設定。User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings.

    警告

    不正確地編輯登錄可能會對系統造成嚴重的損害。Incorrectly editing the registry may severely damage your system. 變更登錄之前,您應該先備份電腦所有的重要資料。Before making changes to the registry, you should back up any valued data on the computer.

  • 如果您使用 /f: on來啟用檔案和目錄名稱完成,請使用 ctrl + D 進行目錄名稱自動完成,並使用 ctrl + f 來完成檔案名。If you enable file and directory name completion by using /f:on, use CTRL+D for directory name completion and CTRL+F for file name completion. 若要在登錄中停用特定的完成字元,請使用空白字元 [0 × 20] 的值,因為它不是有效的控制字元。To disable a particular completion character in the registry, use the value for white space [0×20] because it is not a valid control character.

    • ctrl + DCTRL + F,會處理檔案和目錄名稱的完成。Pressing CTRL+D or CTRL+F, processes the file and directory name completion. 這些按鍵組合函式會將萬用字元附加至 字串 (如果沒有) ,則會建立符合的路徑清單,然後顯示第一個相符的路徑。These key combination functions append a wildcard character to string (if one is not present), builds a list of paths that match, and then displays the first matching path.

      如果沒有相符的路徑,檔案和目錄名稱完成函式會發出嗶聲,且不會變更顯示。If none of the paths match, the file and directory name completion function beeps and does not change the display. 若要在相符路徑的清單中移動,請重複按 ctrl + Dctrl + FTo move through the list of matching paths, press CTRL+D or CTRL+F repeatedly. 若要向後移動清單,請同步選取 SHIFT 鍵和 ctrl + Dctrl + FTo move through the list backwards, press the SHIFT key and CTRL+D or CTRL+F simultaneously. 若要捨棄符合路徑的已儲存清單,並產生新的清單,請編輯 字串 ,然後按下 ctrl + Dctrl + FTo discard the saved list of matching paths and generate a new list, edit string and press CTRL+D or CTRL+F. 如果您在 ctrl + Dctrl + F之間切換,則會捨棄相符路徑的已儲存清單,並產生新的清單。If you switch between CTRL+D and CTRL+F, the saved list of matching paths is discarded and a new list is generated. 按鍵組合 ctrl + dctrl + f 之間的唯一差異在於, ctrl + D 只符合目錄名稱,而 ctrl + F 則符合檔案和目錄名稱。The only difference between the key combinations CTRL+D and CTRL+F is that CTRL+D only matches directory names and CTRL+F matches both file and directory names. 如果您在任何內建目錄命令上使用檔案和目錄名稱完成 (也就是、 CDMDRD) ,則會假設為目錄自動完成。If you use file and directory name completion on any of the built-in directory commands (that is, CD, MD, or RD), directory completion is assumed.

    • 如果您在相符的路徑周圍加上引號,檔案和目錄名稱完成會正確地處理包含空白字元或特殊字元的檔案名。File and directory name completion correctly processes file names that contain white space or special characters if you place quotation marks around the matching path.

    • 您必須使用引號括住下列特殊字元: & < > [] {} ^ =;!You must use quotation marks around the following special characters: & < > [ ] { } ^ = ; ! ' +,' ~ [空白字元]。' + , ` ~ [white space].

    • 如果您提供的資訊包含空格,您必須使用引號括住文字 (例如「電腦名稱稱」 ) 。If the information that you supply contains spaces, you must use quotation marks around the text (for example, "Computer Name").

    • 如果您處理 字串內的檔案和目錄名稱完成,資料指標右邊 路徑 的任何部分都會被捨棄 (在 字串 中) 處理完成的時間點。If you process file and directory name completion from within string, any part of the path to the right of the cursor is discarded (at the point in string where the completion was processed).

其他參考資料Additional References