• Windows 下结束端口占用


    创建文件 .bat 格式保存后执行

    @Echo Off
    :: created by citrus
    
    title=杀掉指定接口进程
    SETLOCAL EnableDelayedExpansion
    for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
      set "DEL=%%a"
    )
    call :ColorText 09 "POWER BY CITRUS"
    echo.
    goto cmdmain
    
    :cmdmain
    set /p port=请输入指定端口:
    
    
    if  "%port%" == "" (
      echo.
      call :ColorText 0c "无效端口"
      echo.
      echo.
      goto cmdchoice		
    )
    
    
    for /f "tokens=5" %%a  in ('netstat /ano ^| findstr %port%') do ( set PidList=%%a)
    
    if  "%PidList%" == "" (
      echo.
      call :ColorText 0c "进程不存在"
      echo.
      echo.
      goto cmdchoice
    )
    
    for /f "tokens=1" %%b in ('tasklist ^| findstr %PidList%') do ( set PName=%%b)
    
    echo.
    echo =========================
    echo.
    echo.
    echo *端口(%port%)的PID是(%PidList%)
    echo.
    echo.
    call :ColorText 0a "        %PName%"
    echo.
    echo.
    echo =========================
    echo.
    set "select="
    
    set/p select=是否终止该进程(0: 否,退出, 1: 是,2:  查看所有进程):
    
    if "%select%"=="0" (goto cmd3)
    if "%select%"=="1" (goto cmd1)
    if "%select%"=="2" (goto cmd2)
    echo.
    call :ColorText 0c "无效字符,即将退出"
    echo.
    echo.
    goto cmd3
    
    :cmdchoice
    set "selectmore="
    
    set/p selectmore=是否查看所有进程(0: 否, 退出,1: 是):
    
    if "%selectmore%"=="0" (goto cmd3)
    if "%selectmore%"=="1" (goto cmd2)
    echo.
    call :ColorText 0c "无效字符,即将退出"
    echo.
    echo.
    goto cmd3
    
    :cmd1
    echo 终止进程中...
    taskkill /f /pid %PidList%
    echo 进程已终止
    PAUSE >null
    
    :cmd2
    netstat /ano
    goto cmdmain
    
    :cmd3
    pause
    exit
    
    :ColorText
    echo off
    <nul set /p ".=%DEL%" > "%~2"
    findstr /v /a:%1 /R "^$" "%~2" nul
    del "%~2" > nul 2>&1
    goto :eof
    
    
  • 相关阅读:
    Heritrix 3.1.0 源码解析(二十五)
    Heritrix 3.1.0 源码解析(二十八)
    获取某年某月的第一天和最后一天的Sql Server函数
    C# ToString()用法汇总
    数据库隐式类型转换
    sql server 中 SET identity_insert on
    Linq To DataTable
    ASP.NET Session详解[转载]
    CSS overflow 属性
    HTML相对路径(Relative Path)和绝对路径(Absolute Path)
  • 原文地址:https://www.cnblogs.com/xmdfn/p/14288959.html
Copyright © 2020-2023  润新知