Solved

closing  command  prompt using shell

Posted on 1998-07-13
6
230 Views
Last Modified: 2010-05-03
'im unzipping files using this command

Private Sub Command1_Click()
MyAppID = Shell("C:\games\Pkunzip.exe -d C:\games\Arcade.zip", 1)
 AppActivate MyAppID

End Sub

'can someone tell me how to make shell close when finished
'without using pif file
0
Comment
Question by:Glynn071198
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 7

Expert Comment

by:tward
ID: 1465665
This does it for me, this also waits for the Shelled process to complete before continuing:

Option Explicit

Private Const INFINITE = -1&
Private Const NORMAL_PRIORITY_CLASS = &H20&

Private Type STARTUPINFO

       cb As Long
       lpReserved As String
       lpDesktop As String
       lpTitle As String
       dwX As Long
       dwY As Long
       dwXSize As Long
       dwYSize As Long
       dwXCountChars As Long
       dwYCountChars As Long
       dwFillAttribute As Long
       dwFlags As Long
       wShowWindow As Integer
       cbReserved2 As Integer
       lpReserved2 As Long
       hStdInput As Long
       hStdOutput As Long
       hStdError As Long

End Type

Private Type PROCESS_INFORMATION
       
       hProcess As Long
       hThread As Long
       dwProcessID As Long
       dwThreadID As Long

End Type

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Sub msiShellAndWait(ByVal CommandLine As String)

  Dim ReturnValue As Long
  Dim Start As STARTUPINFO
  Dim Process As PROCESS_INFORMATION

  ' Initialize the STARTUPINFO structure:
  Start.cb = Len(Start)

  ' Start the shelled application:
  ReturnValue = CreateProcessA(0&, CommandLine, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, Start, Process)

  ' Wait for the shelled application to finish:
  ReturnValue = WaitForSingleObject(Process.hProcess, INFINITE)
  ReturnValue = CloseHandle(Process.hProcess)
 
End Sub

0
 

Author Comment

by:Glynn071198
ID: 1465666
i dont pretend to know what im doing, but i havent had any luck with your code.
i'm sure i did something wrong.

thanks,

ps. still looking.
0
 
LVL 7

Expert Comment

by:tward
ID: 1465667
What problems are you having?  This is basically a replacement for the VB Shell Command.
0
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!

 

Accepted Solution

by:
ohayden earned 10 total points
ID: 1465668
'********** DECLARE THIS IN A MODULE!!!!
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

'********** PUT THIS IN A COMMAND BUTTON!!!!
    Shell "pkzip" ' You can use,vbHide to hide the window
    x = 0
    Do While x = 0
        DoEvents
        x = FindWindow(vbNullString, "Finished - pkzip")
    Loop
    y = PostMessage(x), &H10, vbNull, vbNull)

' Make the "Finished - pkzip" is the actual CAPTION of the
' window you are trying to CLOSE!!!! FindWindow will get the
' handle and PostMessage with &H10 will close it!!!!

' E-mail me at silent@alle.com if u need help!
0
 

Expert Comment

by:ohayden
ID: 1465669
my bad....

change this line...
    y = PostMessage(x), &H10, vbNull, vbNull)

to

    y = PostMessage(x, &H10, vbNull, vbNull)

0
 

Author Comment

by:Glynn071198
ID: 1465670
thanks,
youve been a great help
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB6 / DAO 3.6 / run time error: Couldn't find installable ISAM 7 119
Saving history changes to sub form 4 52
VBA: Select SQL query based on a config Sheet v2 11 52
vbModal 12 66
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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