本帖最后由 lincc0519 于 2012-12-16 22:52 编辑
我也发一个,这个代码能解决start命令调用的情况,但在start /b这种情况下会出现2个进程共用一个窗口,本来想结束一个进程,但这样就失去了start /b命令的原意,同时新窗口下要求pause的情况,所以也就没用处理,要真处理还真是个麻烦事!代码只在windows xp下测试过!- @echo off&setlocal enabledelayedexpansion
- doskey /history|findstr .>nul
- if !errorlevel! equ 0 echo cmd命令调用执行&exit/b
- set str=
- for /l %%a in (1,1,10) do set str=!str!!random!
- if [%1]==[] (
- start /b "" "%~nx0" !str!>nul
- set com=echo.
- ) else (
- set com=pause
- )
- !com!>nul
- for /f "skip=1 tokens=1,2" %%a in ('wmic process where "commandline='c:\\windows\\system32\\cmd.exe /k "%~nx0" !str!'" get processid^,parentprocessid') do (
- set /a pid=%%b,ppid=%%a
- )
- taskkill /pid !pid! /t /f 1>nul 2>nul
- set pid=!ppid!
- for /f "skip=1" %%a in ('wmic process where "processid=!pid!" get parentprocessid') do set ppid=%%a
- for /f "skip=1" %%a in ('wmic process where "processid=!ppid!" get caption') do set name=%%a
- if /i !name!==explorer.exe echo windows操作界面执行&pause>nul&exit/b
- if /i !name!==cmd.exe echo cmd命令调用执行&exit/b
- echo !name!程序执行&exit/b
复制代码
|