昨天晚上写vb程序。
使用Shell()函数,去重复执行1个Dos的程序。
实现批处理解压缩功能。
但是,当Shell()执行6000多次作用,执行到Shell()这句的时候,告诉我:“错误5,无效的系统调用或参数”。
然后,伴随着,我的windows xp系统里的,其他程序也基本上打不开了,告诉我:“系统资源不足”。我开始猜测,可能是我拿C++写的Dos程序的内存泄露问题,反复查阅,没有发现问题。
我又找来了别人写的另1个Dos程序,错误依旧。
所以,我排除了执行的exe的问题。
那么问题就只剩下Shell和我为了配合Shell而调用的几个API。希望高手们能帮我看看,很急。
在别处,都看不到类似的提问,所以,我就发帖问了。求解。代码贴上吧:Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwProcessld As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Const PROCESS_QUERY_INFORMATION = 1024
Const STILL_ACTIVE = 259Private Sub Command1_Click()
    Const inFile As String = "c:\1.bin"
    Const outFile As String = "c:\1_Unzip.bin"    Dim i As Long
    i = 0    Do
        i = i + 1
        Command1.Caption = Str(i)'纯粹为了显示计数
        
        '调用解压缩程序
        ShellWait App.Path & "\unzip.exe " & inFile & " " & outFile
        
        '删除解压缩的文件,然后反复试验
        Kill outFile
    Loop
End Sub'ShellWait是我封装的一个方法,作用是等待Shell执行的程序关闭,再执行下面的语句
Private Sub ShellWait(PathName As String, Optional WindowStyle As VbAppWinStyle = vbMinimizedFocus)
    Dim hShell As Long
    Dim hProc As Long
    Dim iExit As Long
    hShell = Shell(PathName, WindowStyle)
    hProc = OpenProcess(PROCESS_QUERY_INFORMATION, False, hShell)
    Do
        GetExitCodeProcess hProc, iExit
        DoEvents
    Loop While iExit = STILL_ACTIVE
End Sub

解决方案 »

  1.   

    这类问题造成的主要原因是 调用的次数过多 或过快!应该是过多吧。
    因为,我把VB程序关闭了。
    我的XP系统,基本上,其他程序也都打不开了。
    告诉我:“系统资源不足”。
      

  2.   

    1:unzip.exe 运行完能不能自己关闭?
    2:shell是异步执行,你一直调用可能会导致数千个unzip.exe 在运行,当然不行了