close 7za.exe after opening it using shell command

Posted on 2012-09-06
Last Modified: 2012-09-07
i am opening 7za.exe to extract an exe file with in vb6 using the following command

Open App.path & "\run.bat" For Output As #1
    Print #1, "7za x " & path & " -p123#Password -od:\targetfolder2"
    Print #1, "exit"
    Close #1
    Shell App.path & "\run.bat", vbHide

it is working as a charm, but the problem is 7za.exe and cmd.exe is piling up in taskmanager when i am doing similar operations with dynamic files. how to close 7za.exe and cmd.exe after executing it. Please help :(
Question by:anbuvec
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Have you tried running 7za directly with Shell() instead of using a .bat?

    Accepted Solution

    Thank you Idle_Mind. i have just used another logic :D

    i have created another batch file to forcefully delete 7za.exe from taskmanager using taskkill

    Open App.path & "\run.bat" For Output As #1
    Print #1, "taskkill /im 7za.exe /f"
    close #1

    it works perfectly.... ha ha... i am just posting this so that some one else can also use this method

    Author Comment

    I've requested that this question be closed as follows:

    Accepted answer: 0 points for anbuvec's comment #a38372032

    for the following reason:

    i have figured out the problem my self.... i found a solution for my problem
    LVL 15

    Expert Comment

    Hi anbuvec,
    your solution is bad solution!

    Try this:
      Dim sPathToExe As String
      Dim sArchiveName As String
      Dim sTargetFolder As String
      Dim sPwd As String
      Dim nFileNumber As Long
      nFileNumber = FreeFile
      sPathToExe = "C:\Program Files\7-Zip" 'replace with your path
      sArchiveName = App.Path & "\" & "test.7za" 'replace with your archive file name
      sTargetFolder = "c:\temp" 'replace with your path
      sPwd = "1secret" 'replace with your password
      Open App.Path & "\run.bat" For Output As #nFileNumber
      Print #nFileNumber, sPathToExe & "\" & "7za.exe x " & sArchiveName & " -p" & sPwd & " -o" & sTargetFolder
      Print #nFileNumber, "exit"
      Close #nFileNumber
      Shell App.Path & "\run.bat", vbHide

    Open in new window

    Never use:
          Open * As #1
    Use always:
          Dim nFileNumber As Long
          nFileNumber = FreeFile
          Open * As #nFileNumber

    FreeFile returns an Integer representing the next file number available for use by the Open statement.
    Use FreeFile to supply a file number that is not already in use.

    Author Comment

    Hi eemit,

    Thank you very much for your suggestion... but i really disagree with the statement that it is a bad solution. there is no bad or good solution, solution is a solution, ultimately we need some thing to make it work. which my method also does and more over this is just a temporary process which will not harm any other process or procedure so i am happy with my solution and your solution is definitely a good one... but mine is also a solution and not a bad solution.
    LVL 15

    Expert Comment

    I apologize for my harsh words.
    Please use FreeFile to supply a file number that is not already in use.

    My two suggestions:
    1) Don't close your questions too quickly.
    2) Assign more points to an open question to get more people to answer your question.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now