这个我不会, 但有一种隐藏运行的技术- @echo off & setlocal enabledelayedexpansion
- if /i "%1" equ "hide" goto begin
- if /i "%1" equ "show" goto begin
-
- set /p show=需要显示窗口界面吗^(y/n^)[直接回车=不显示]:)
- if /i "%show:~0,1%" equ "y" goto begin
- (call :showWindow hide)
-
- :begin
-
- call :foundACName ACName
- set "ipa=192.168.1.101" & set "ipb=192.168.1.102" & set "mask=255.255.255.0" & set "gateway=192.168.1.1"
- set /a ms=2 & rem ms 为时间间隔
- for /l %%k in (0 0 0) do (
- set /a "diff=1!time:~3,2!-100+60-mm, diff%%=60"
- if !diff! geq !ms! ( set /a mm=1!time:~3,2!-100
- for /f "tokens=2 delims=[]" %%i in ('ping -n 1 %computername% ^| find "["') do (
- if "%%i"=="!ipa!" (netsh interface ip set address name="!ACName!" source=static addr=!ipb! mask=!mask! gateway=!gateway! 1
- ) else (
- netsh interface ip set address name="!ACName!" source=static addr=!ipa! mask=!mask! gateway=!gateway! 1
- )
- for /f "tokens=2 delims=[]" %%a in ('ping -n 1 %computername% ^| find "["') do echo %%a
- )
- )
- )
- exit /b
-
- :foundACName ACName rem 找出当前活动连接的名称
- for /f "tokens=2 delims=[]" %%i in ('ping -n 1 %computername% ^| find "["') do (
- for /f "skip=1" %%a in ('wmic nicconfig where "ipenabled='true'" get index') do (
- for /f "delims=}{" %%b in ('wmic nicconfig where "index=%%a" get ipaddress') do (
- if "%%~b"=="%%i" for /f "tokens=1-2 delims==" %%c in ('wmic nic where "index=%%a" get NetConnectionID /value') do (
- for /f "delims=" %%z in ("%%d") do set "_%%c=%%z"
- )
- )
- )
- )
- set %1=!_NetConnectionID!&echo 当前活动连接为: "!%1!"
- exit /b
-
- :showWindow
- if /i "%1" equ "hide" (set intWindowStyle=0) else (set intWindowStyle=5)
- mshta vbscript:createobject("wscript.shell").run("%~snx0 %1",!intWindowStyle!)(window.close)&&exit
- exit /b
复制代码 要想关闭隐藏的 cmd , 可以用一种野蛮的方式关闭所有的 cmd- taskkill /f /t /im cmd.exe
复制代码
[ 本帖最后由 neorobin 于 2010-6-24 23:07 编辑 ] |