Solved

closing  command  prompt using shell

Posted on 1998-07-13
6
226 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

860 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