CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: VB & WinZip

  1. #1
    Join Date
    Oct 1998
    Posts
    1

    VB & WinZip



    I am new to Vb but have done alot of VBA with Access. I now wish to build a small utility that will open WinZip or PkZip in the background and then I can copy a couple of database files to it and then close Winzip/Pkzip after the copying is complete. I would also like to find out how to close a open application through VB.


    Any help would be appreciated.


    Baz...........(:0)..................

  2. #2
    Join Date
    Nov 1998
    Posts
    1

    Re: VB & WinZip



    The Zlib library is a public domain library for zip file compression. It is written in C++ however, so you would need to compile it into a dll to use it in VB. I don't know where a current site for Zlib is.


    If that is too much trouble you could use an Active X control. I have seen at least a couple that handle zip files.


    Good luck,


    Fred

  3. #3
    Join Date
    Mar 2001
    Posts
    4

    Re: VB & WinZip

    You can use the Api-functions FindWindow and SendMessage to solve your problem.
    With findwindow you can search for the window, you want to close.
    Then you send a WM_CLOSE command with the SendMessage command.
    SendMessage accepts 2 params. You need only to specify one of them.

    If youre not sure about the class/ or windowname start spyxx.exe from the vs_studio, it will list you class & window name of every running app.

    Regards

    Thomas


    public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (byval lpClassName as string, byval lpWindowName as string) as Long
    public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, lParam as Any) as Long
    public Const WM_CLOSE = &H10

    'this function finds a window and closes it
    public Function FindWin(taskname as string) as Boolean
    Dim result as Long
    Dim leave as Boolean
    result = FindWindow(vbNullString, taskname)
    If result > 0 then
    result = SendMessage(result, WM_CLOSE, 0, vbNullString)

    dat = time
    'test if window has closed
    Do While leave = false
    DoEvents
    datIn = time
    result = FindWindow(vbNullString, taskname)
    If result = 0 then
    leave = true
    Exit Do
    End If
    If CSng(datIn - dat) > 0.0005 then
    leave = true
    End If
    Loop
    result = FindWindow(vbNullString, taskname)
    If result <> 0 then
    MsgBox "Fenster konnte nicht geschlossen werden"
    FindWin = false
    Exit Function
    End If
    else

    End If
    FindWin = true
    End Function





  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: VB & WinZip

    c = Shell("d:\temp\pkunzip.exe d:\temp\t001015.zip d:\temp", vbHide)




    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: VB & WinZip

    '========another way of doing it========
    ' Inputs:'Example:
    'source = app.path & "source.exe"
    'target = app.path & "target.zip"
    'zip = true (compress)
    'zip = false(uncompress)



    Function winZipit(ByVal source As String, ByVal target As String, ByVal zip As Boolean)
    zipIT = App.Path & "winzip32 -a"
    unzipIT = App.Path & "winzip32 -e "


    If zip = True Then
    Shell (zipIT & target & source)
    Else: Shell (unzipIT & target & source)
    End If
    End Function


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  6. #6
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: VB & WinZip

    Iouri,
    Your reply regarding running WinZip from VB is something I have been looking for for some time.
    '
    The UnZip portion, however, unpacks the entire .Zip library. DO you know of a way to unpack just one file?

    Thanks in advance,


    John G

  7. #7
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: VB & WinZip

    'Here all the options for extracting files


    Extracting Files:
    '=========
    The command format is:
    winzip[32].exe -e [options] filename[.zip] directory
    where:
    -e Is required.
    options
    -o and -j stand For "Overwrite existing files without prompting" and
    "Junk pathnames", respectively. Unless -j is specified, directory
    information is used.
    -s allows specification of a password. The password can be enclosed
    In quotes, For example, -s"Secret Password". Note that passwords are
    case-sensitive.
    filename.zip
    Specifies the name of the ZIP involved. Be sure To specify the full
    filename (including the directory).
    directory
    Is the name of the directory to which the files are extracted. If the
    directory does Not exist it is created.
    Notes:
    * VERY IMPORTANT: Always specify complete filenames, including the full
    path name and drive letter, For all file IDs.
    * To run WinZip in a minimized inactive icon use the "-min" option.
    When specified this option must be the first option.
    * Only operations involving the built-in zip and unzip are supported.
    * Enclose Long filenames on the command line in quotes.
    * NO leading or trailing blanks, or blank lines For readability, are
    allowed In list ("@") files.
    * The action and Each option on the command line must be separated
    from the others by at least one space.
    * WinZip can be used To compress files With cc:Mail . Change the
    compress= line in the [cc:Mail] section of the appropriate WMAIL.INI
    files To specify the full path For WinZip followed by "-a %1 @%2".


    For example, If WinZip is installed in your c:\winzip directory,
    specify
    compress=c:\winzip\winzip.exe -a %1 @%2



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured