Solved

to Mcrider

Posted on 2000-03-29
2
566 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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now