Solved

to Mcrider

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
JSON Response and request in VB6 application 11 805
Protecting vb6 & .Net code Obfuscation 18 183
TT Auto Dashboard 13 101
VBA: copy range dynamically based on config sheet v2 3 55
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

749 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