errorlevel变量出错 批处理目的:当拖入文件名中含有“目的是找不到我”就将变量count清空,否则就自增1.

errorlevel变量出错 批处理目的:当拖入文件名中含有“目的是找不到我”就将变量count清空,否则就自增1.,第1张

errorlevel是系统内置的错误码返回变量,不允许自己赋值,命令执行时会自动赋值的!如果自行赋值,系统只能读取你所设置的值,而真实的值“隐身”了,直到你执行

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11201451.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存