Solved

closing  command  prompt using shell

Posted on 1998-07-13
6
213 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

746 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

9 Experts available now in Live!

Get 1:1 Help Now