Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 781
  • Last Modified:

close 7za.exe after opening it using shell command

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 :(
  • 3
  • 2
1 Solution
Mike TomlinsonMiddle School Assistant TeacherCommented:
Have you tried running 7za directly with Shell() instead of using a .bat?
anbuvecAuthor Commented:
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
anbuvecAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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.
anbuvecAuthor Commented:
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.
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now