Solved

to Mcrider

Posted on 2000-03-29
2
577 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

816 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

12 Experts available now in Live!

Get 1:1 Help Now