2017-08-17 53 views
0

我創建了一個簡單的批處理文件,用於將連接模式更改爲無線連接到局域網,反之亦然(我們公司有時與我們的Internet連接有困難,並會建議我們更改連接)。CMD選擇查詢

下面是代碼(我只是在腳本一個新手):

@ECHO off 
cls 
:start 
ECHO. 
ECHO ********************************************* 
ECHO Choose Connection Mode (!!!Case Sensitive!!!) 
ECHO ********************************************* 
ECHO. 
ECHO [W]ireless Mode On 
ECHO [L]ocal Area Connection Mode On 
ECHO [E]xit 
ECHO. 
set choice= 
set /p choice=Select Connection Mode: 
ECHO. 
if not '%choice%'=='' set choice=%choice:~0,1% 
if '%choice%'=='W' goto wireless 
if '%choice%'=='L' goto local 
if '%choice%'=='E' goto end 
ECHO "%choice%" is not valid, try again 
ECHO. 
goto start 
:wireless 
netsh interface set interface "Local Area Connection" DISABLED 
netsh interface set interface "Wireless Network Connection" ENABLED 
ECHO. 
goto end 
:local 
netsh interface set interface "Wireless Network Connection" DISABLED 
netsh interface set interface "Local Area Connection" ENABLED 
goto end 
:end 

能有人請解釋這條線?

if not '%choice%'=='' set choice=%choice:~0,1% 

我複製並編輯了我找到的腳本。只需要知道這部分以便更好地理解

回答

0

該問題行將進行檢查以確保choice不是空字符串,然後提取它的任何第一個字符,並將其指定回choice。你可以在SS64's page on substring syntax in CMD找到關於子串提取的更多信息。

整個SS64 reference site對查找bash,CMD,PowerShell和其他腳本語言的語法很有用。我把它加入書籤...

+0

Got it!非常感謝你! – 7thGen

+0

您可能想要考慮修改此選項以使用['CHOICE'](https://ss64.com/nt/choice.html)命令,該命令也在SS64中記錄。 –