• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 612
  • Last Modified:

to Mcrider

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
BHimmerick
Asked:
BHimmerick
1 Solution
 
mcriderCommented:
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
 
BHimmerickAuthor Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now