?
Solved

closing  command  prompt using shell

Posted on 1998-07-13
6
Medium Priority
?
245 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Accepted Solution

by:
ohayden earned 40 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

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 how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

777 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