Solved

closing  command  prompt using shell

Posted on 1998-07-13
6
223 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to compare ms sql hashbytes results within vb6 5 76
How to Add / Edit Windows Menu 4 61
Macro Excel - Multiple If conditions 2 73
Excel Automation VBA 19 73
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

803 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