Solved

to Mcrider

Posted on 2000-03-29
2
581 Views
Last Modified: 2007-10-18
You recommended a solution for someone attempting to use the Winzip self extractor utility.  I'm attempting the same thing.  I'm using the following code that someone posted on experts exchange. I have the Zip and Unzip working fine but I can't get the create self extractor to work.  Any suggestions:
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
            ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, _
            ByVal dwMilliseconds As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Const WinZipEXCPath = "C:\Program Files\Winzip\Wzsepe32.exe"
Const WinZipEXEPath = "C:\Program Files\WinZip\Winzip32.exe"
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFF  ' Wait forever
Const WAIT_OBJECT_0 = 0   ' The state of the specified object is signaled
Const WAIT_TIMEOUT = &H102  ' The time-out interval elapsed and the object’s state is nonsignaled.

Public Function ShellExecAndWait(ProgramPathAndName As String, Optional cmd As String = "")
Dim lPid As Long
Dim lHnd As Long
Dim lRet As Long

If Trim(ProgramPathAndName) = "" Then Exit Function

lPid = Shell(Trim(ProgramPathAndName) + " " + Trim(cmd), vbNormalFocus)
If lPid <> 0 Then
    'Get a handle to the shelled process.
    lHnd = OpenProcess(SYNCHRONIZE, 0, lPid)
    'If successful, wait for the application to end and close the handle.
    If lHnd <> 0 Then
        lRet = WaitForSingleObject(lHnd, INFINITE)
        CloseHandle (lHnd)
        End If
    'MsgBox "Just terminated.", vbInformation, "Shelled Application"
    End If
End Function

*****
I've attempted:
ShellExecAndWait WinZipEXCPath, "c:\Test\Four.zip"
I need it to run silently.


0
Comment
Question by:BHimmerick
2 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 200 total points
ID: 2666859
Add the following code to a MODULE, then you can do this:


   ProgHandle = Shell("C:\Program Files\Winzip\Wzsepe32.exe c:\Test\Four.zip", vbNormalFocus)
   WaitOnActiveShell ProgHandle

Your program will remain active, however execution will stop on the WaitOnActiveShell call until the shelled process has terminated.

Otherwize, you can do this:

   ExecCmd "C:\Program Files\Winzip\Wzsepe32.exe c:\Test\Four.zip"

and you program will freeze until the shelled program terminates...

Hope this helps!


Cheers!®©

PUT THIS CODE IN A MODULE:
---------------------------------------------------------------------------------------------------
    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Public Const INFINITE = -1&
   
    Global ProgHandle As Long
   
    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
   
    Declare Sub SleepAPI Lib "kernel32" _
        Alias "Sleep" (ByVal dwMilliseconds As Long)
   
    Declare Function GetExitCodeProcess Lib "kernel32" _
        (ByVal hProcess As Long, lpExitCode As Long) As Long
   
    Declare Function SysSetFocus Lib "user32" Alias "SetFocus" _
        (ByVal hwnd As Long) As Long
   
    Private Declare Function OpenProcess Lib "kernel32" (ByVal _
        dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
        ByVal dwProcessId As Long) As Long
   
    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 Function ExecCmd(cmdline As String)
        Dim ret As Long
        Dim proc As PROCESS_INFORMATION
        Dim start As STARTUPINFO
       
        ' Initialize the STARTUPINFO structure:
        start.cb = Len(start)
       
        ' Start the shelled application:
        ret = CreateProcessA(0&, cmdline, 0&, 0&, 1&, _
        NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
       
        ' Wait for the shelled application to finish:
        ret = WaitForSingleObject(proc.hProcess, INFINITE)
        Call GetExitCodeProcess(proc.hProcess, ret)
        Call CloseHandle(proc.hThread)
        Call CloseHandle(proc.hProcess)
        ExecCmd = ret
    End Function
   
    Function IsActive(hprog) As Long
        Dim hProc, RetVal As Long
        hProc = OpenProcess(0, False, hprog)
        If hProc <> 0 Then GetExitCodeProcess hProc, RetVal
        IsActive = (RetVal = 259)
        CloseHandle hProc
    End Function
   
    Function WaitOnActiveShell(hprog)
        Do
            If IsActive(hprog) Then
                DoEvents
                SleepAPI 55
            Else
                Exit Do
            End If
        Loop
    End Function
0
 

Author Comment

by:BHimmerick
ID: 2667016
Actually thanks for responding but I did figure it out.  Notice: In my original code that the Self Extractor name is Wzsepe32.  This is the personal edition which from what I've seen on Winzip.com will not accept arguements.  I subsequently downloaded the full version of the .exe.  Different exes in works wonderfully.  I found the answer this morning but was unable to post the answer.  The correct command line syntax is as follows:  winzipse.exe -win32 "c:\Test\Four.zip".
Thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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 …
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.
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…

809 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