@echo off
:start
cls
echo.
echo ** Disable Anti-virus Trend-Micro **
echo.
REM Step 1: Set the 5-digit number
if "%~1"=="" (
SET /p number=Enter Store Code:
) else (
SET /A "number=%~1"
)
REM Check if the input is empty or not 5 digits
if "%number%"=="" (
goto start
) else if not "%number:~5,1%"=="" (
goto start
)
REM Step 2: Convert to pthxxxxx
SET code=pth%number%
SET option_1st=-UTRANSF -PFSNART
SET option_2nd=-Usa -Ppassword123
REM Step 3: Resolve and modify IP from pthxxxxx
echo Checking %code% connection....
for /F "tokens=2 delims=[]" %%a in ('ping -4 -n 2 -w 2000 %code% ^| findstr "["') do SET IP=%%a
REM Step 4: Check if IP is OFFLINE or ONLINE, if so, display error message
if "%IP%"=="" (
cls
echo Enter Store code: %number%
echo %code% OFFLINE.
goto start
) else (
cls
echo Enter Store code: %number%
echo %code% ONLINE.
)
REM Step 6: Display options and connect to selected device via sqlcmd
:menu
echo Store: %number%
echo Select the device to connect to:
echo 1. POS1 (.60)
echo 2. POS2 (.61)
echo 3. POS3 (.62)
rem echo 8. PTH (.8)
set /p choice=Enter your choice:
REM Determine the IP address based on user's choice
set "device_ip="
if "%choice%"=="1" set "device_ip=%IP:~0,-1%60"
if "%choice%"=="2" set "device_ip=%IP:~0,-1%61"
if "%choice%"=="3" set "device_ip=%IP:~0,-1%62"
if "%choice%"=="q" goto :start
REM Connect to the selected device via sqlcmd
if defined device_ip (
echo Connecting to %device_ip%
REM Try using option_1st first
if "%choice%"=="1" (
sqlcmd -S %device_ip% %option_1st% -i \\172.28.8.7\mis\it_ServiceDesk\ITSD\2083761-Prapun\disable_trendmicro.sql -h-1
) else if "%choice%"=="2" (
sqlcmd -S %device_ip% %option_1st% -i \\172.28.8.7\mis\it_ServiceDesk\ITSD\2083761-Prapun\disable_trendmicro.sql -h-1
) else if "%choice%"=="3" (
sqlcmd -S %device_ip% %option_1st% -i \\172.28.8.7\mis\it_ServiceDesk\ITSD\2083761-Prapun\disable_trendmicro.sql -h-1
)
REM Check ERRORLEVEL to see if the previous command failed
if ERRORLEVEL 1 (
echo First option failed, trying second option...
if "%choice%"=="1" (
sqlcmd -S %device_ip% %option_2nd% -i \\172.28.8.7\mis\it_ServiceDesk\ITSD\2083761-Prapun\disable_trendmicro.sql -h-1
) else if "%choice%"=="2" (
sqlcmd -S %device_ip% %option_2nd% -i \\172.28.8.7\mis\it_ServiceDesk\ITSD\2083761-Prapun\disable_trendmicro.sql -h-1
) else if "%choice%"=="3" (
sqlcmd -S %device_ip% %option_2nd% -i \\172.28.8.7\mis\it_ServiceDesk\ITSD\2083761-Prapun\disable_trendmicro.sql -h-1
)
)
pause > nul
cls
goto menu
) else (
cls
echo Invalid choice, please try again.
goto menu
)
set number=
goto start
เพิ่ม function input ip address
ในการเพิ่มฟังก์ชันสำหรับให้ผู้ใช้สามารถป้อนที่อยู่ IP แทนที่จะต้องใช้ pthxxxxx คุณจะต้องทำการแก้ไขสคริปต์ให้แสดงคำถามใหม่ที่ถามผู้ใช้ว่าต้องการป้อน IP เองหรือไม่ ถ้าผู้ใช้อยากจะป้อน IP เอง ให้ข้ามขั้นตอนการ ping และใช้ IP ที่ผู้ใช้ป้อน
ต่อไปนี้เป็นตัวอย่างของวิธีที่คุณสามารถปรับปรุงสคริปต์ได้:
@echo off
:start
cls
echo.
echo ** Disable Anti-virus Trend-Micro **
echo.
REM Step 1: Set the 5-digit number or IP address
if "%~1"=="" (
SET /p number=Enter Store Code (or IP Address):
) else (
SET "number=%~1"
)
REM Check if the input is empty or not 5 digits
if "%number%"=="" (
goto start
) else if not "%number:~5,1%"=="" (
goto start
)
REM Ask if user wants to enter an IP address
SET /p input_ip=Do you want to enter an IP address instead of using the store code? (y/n):
if /I "%input_ip%"=="y" (
SET /p IP=Enter IP Address:
SET "code=pth%number%"
) else (
REM Step 2: Convert to pthxxxxx
SET code=pth%number%
REM Step 3: Resolve IP from pthxxxxx
echo Checking %code% connection....
for /F "tokens=2 delims=[]" %%a in ('ping -4 -n 2 -w 2000 %code% ^| findstr "["') do SET IP=%%a
REM Step 4: Check if IP is OFFLINE or ONLINE
if "%IP%"=="" (
cls
echo Enter Store code: %number%
echo %code% OFFLINE.
goto start
) else (
cls
echo Enter Store code: %number%
echo %code% ONLINE.
)
)
REM Step 6: Display options and connect to selected device via sqlcmd
:menu
echo Store: %number%
echo Select the device to connect to:
echo 1. POS1 (.60)
echo 2. POS2 (.61)
echo 3. POS3 (.62)
rem echo 8. PTH (.8)
set /p choice=Enter your choice:
REM Determine the IP address based on user's choice
set "device_ip="
if "%choice%"=="1" set "device_ip=%IP:~0,-1%60"
if "%choice%"=="2" set "device_ip=%IP:~0,-1%61"
if "%choice%"=="3" set "device_ip=%IP:~0,-1%62"
if "%choice%"=="q" goto :start
REM Connect to the selected device via sqlcmd
if defined device_ip (
echo Connecting to %device_ip%
REM Try using option_1st first
if "%choice%"=="1" (
sqlcmd -S %device_ip% %option_1st% -i \\172.28.8.7\mis\it_ServiceDesk\ITSD\2083761-Prapun\disable_trendmicro.sql -h-1
) else if "%choice%"=="2" (
sqlcmd -S %device_ip% %option_1st% -i \\172.28.8.7\mis\it_ServiceDesk\ITSD\2083761-Prapun\disable_trendmicro.sql -h-1
) else if "%choice%"=="3" (
sqlcmd -S %device_ip% %option_1st% -i \\172.28.8.7\mis\it_ServiceDesk\ITSD\2083761-Prapun\disable_trendmicro.sql -h-1
)
REM Check ERRORLEVEL to see if the previous command failed
if ERRORLEVEL 1 (
echo First option failed, trying second option...
if "%choice%"=="1" (
sqlcmd -S %device_ip% %option_2nd% -i \\172.28.8.7\mis\it_ServiceDesk\ITSD\2083761-Prapun\disable_trendmicro.sql -h-1
) else if "%choice%"=="2" (
sqlcmd -S %device_ip% %option_2nd% -i \\172.28.8.7\mis\it_ServiceDesk\ITSD\2083761-Prapun\disable_trendmicro.sql -h-1
) else if "%choice%"=="3" (
sqlcmd -S %device_ip% %option_2nd% -i \\172.28.8.7\mis\it_ServiceDesk\ITSD\2083761-Prapun\disable_trendmicro.sql -h-1
)
)
pause > nul
cls
goto menu
) else (
cls
echo Invalid choice, please try again.
goto menu
)
set number=
goto start
คำอธิบายการเปลี่ยนแปลง:
- มีการถามผู้ใช้ว่าต้องการป้อน IP Address เองหรือไม่ (enter an IP address instead of using the store code).
- หากผู้ใช้ตอบ “y” จะให้ป้อนที่อยู่ IP แทนที่จะใช้
pthxxxxx.
- ถ้าผู้ใช้ไม่ป้อน IP จะให้ทำการตรวจสอบความเชื่อมต่อของ
pthxxxxx ตามเดิม
การเปลี่ยนแปลงนี้จะทำให้สามารถใช้งานได้ทั้งสองวิธี: ป้อน Store Code หรือป้อน IP Address โดยตรง