set errorlevel=
后,真实的值才会现身!
===================================================================
可改为:
@echo off
:start
set /p file=拖入任意文件:
echo %file%
echo %file%|find "目的是找不到我">nul
echo 返回码%errorlevel%
if "%errorlevel%"=="0" (
pause>nul
set count=
) else (
set errorlevel=0
)
echo 返回码%errorlevel%
echo %count%
pause
set /a count=count+1
set errorlevel=
goto start
===================================================================
根据你标题的说法,应该这样做:
@echo off
:start
set /p file=拖入任意文件:
echo %file%|find "目的是找不到我"
if "%errorlevel%"=="0" (set count=) else (set /a count+=1)
echo %count%
pause
goto start
===================================================================
——sp@cai
没有简单的。唉,编程本来就是个麻烦事。模块中声明:
Public Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
窗体代码:
Private Sub Command1_Click()
' TerminateProcess -1, 1125 'also can
ExitProcess 1234
End Sub
测试程序:
模块声明:
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, uExitCode As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hProcess As Long) As Long
窗体代码:
Const PROCESS_QUERY_INFORMATION = &H400
Const PROCESS_TERMINATE = &H1
Dim ret As Long
Dim h As Long
Dim pid As Long
Private Sub Command1_Click()
If h Then
GetExitCodeProcess h, ret
MsgBox ret
Else
MsgBox "fail"
End If
End Sub
Private Sub Form_Load()
pid = 1448
h = OpenProcess(PROCESS_QUERY_INFORMATION + PROCESS_TERMINATE, 0, pid)
End Sub
Private Sub Form_Unload(Cancel As Integer)
If h Then CloseHandle h
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)