pkzip problem

rodneyb

Registered User.
Local time
Today, 02:20
Joined
Jul 3, 2003
Messages
84
Hi,

I have currently got some code within an Access97 app which is used to zip some files to a specified directory. I am achieving this using pkzip:

Call Shell("pkzip25.exe" & " -add -move " & archivePath & "\" & filename & " " & archivePath & "\*.mdb", vbHide)

This works fine when the code is initially called but if this shell code is called a second time within a few seconds of the first call, an error comes up basically saying that it couldn't do the second zip because the first zip is still zipping. I'm just wondering if there is some sort of code which I could use to check and see if pkzip is currently in use - if it is not then I can use the command above, otherwise I can wait a certain length of time before trying again.

Any thoughts, comments would be greatly appreciated.
Cheers
 
you can retain the shell double (i think) by not calling it but using it as a function

dim x as double
x = shell

then you can use appactivate to check if its still active. and wait for it, I think there is something of a sample out there somewhere.

Regards
 
If that doesn't work (I'm sure it didn't when I tried it years ago) try this:
Code:
'Type Definitons
'===============
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

'Constants
'=========
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&

'Declarations
'============
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 Sub ExecCmd(sCmdLine As String)
'Executes cmdline and waits for it to finsh
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim Ret As Long

' Initialize the STARTUPINFO structure:
Start.cb = Len(Start)

' Start the shelled application:
Ret = CreateProcessA(0&, sCmdLine, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, Start, proc)

' Wait for the shelled application to finish:
Ret = WaitForSingleObject(proc.hProcess, INFINITE)
Ret = CloseHandle(proc.hProcess)
End Sub
Then replace shell with ExecCmd.
 
Using the API offcourse is much better, but also much more complex....

Regards
 
thanks guys for your help.

I tried appactivate but could not get this to work correctly therefore I implemented Cables code which works great.

The only thing I would like to modify is instead of the dos window displaying on top of the access app in order to run pkzip - I would rather have it hidden while executing in the background.

Also because of the size of the database this takes a while to zip up, therefore it would be nice to call the pkzip command asynchronously so that the user can carry on working on the access app without waiting for the zip to finish.

I guess ideally I would still rather have the access code check to see if pkzip is currently running, if it is running then wait - otherwise zip.

Cheers.
 
urm they can't work on with the data if its currently being zipped!

To do what your thinking you will need to loop through the list of windows and match title's, which I think I did work out once...but forgotten now:) I do remember a problem actually getting the window titles for command prompts. A search on this forum or a VB one might lead to sommit:)
 
ah but users can work on the application while it is being zipped - users can't work on the app when the db files are 'copied', but they can work on the app when winzip is called to zip a file.

This is the whole dilema - because winzip is still trying to zip the copied files whilst the application is actively being used by the user (ie once the shell command has been executed by access the code continues on while winzip works away in the background). The user then selects the button to backup the db a second time before the initial zip has not completed by winzip in the background - this is where the error occurs.
 
well that should be easy to stop!

the first line should check for the existance of the zipped file...if it does exist then cancel the sub.
This can be used to check for existance of file/dir.
Code:
Public Function Exists(sFileName As String) As Boolean
'check if a file exists
Dim l As Long

On Error GoTo ErrHand

Exists = False

If InStr(sFileName, ".") <> 0 Then  'check for extension, hence file
    l = FileLen(sFileName)
    If l <> 0 Then
        Exists = True
    End If
Else                                'we're not a file, we're a directory/folder
    If Dir(sFileName, vbDirectory) <> "" Then
        Exists = True
    End If
End If

Exit Function
ErrHand:
    Exists = False                  'any error then defualt to false
End Function
But you 'will' get an warning if you try to zip a backend database that is in use...winzip defo gives me one.
 

Users who are viewing this thread

Back
Top Bottom