Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Basic 6.0, Zipping files and job scheduler 3

Status
Not open for further replies.

jkb17

Programmer
Nov 27, 2000
156
US
I have created a visual basic app that iterates through a loop and creates certain folders with excel files. i want to zip certain folders together into a self-extracting zip file. I assume that I will use some software such as Winzip and thne execute a command line command using the Shell() command in Visual Basic. Is there any advice on which zip utility to use and what is the cheapest route?

Also, this batch process I have can take some time (depending on the date ranges specified by the user). And would work much better as a scheduled job rather then a manually, run program. Is there any scheduling utilities out there that I should investigate? I do utilize MS SQL Server but the end user will not have access (nor any clue on how to) schedule a job within SQL Server.

Thanks for any help and let me know if you need more info then that.
 
I previously looked into zipping files from a VB application, but I found that WinZip did not offer the command line functionality that I needed. Instead I used PKZip, which also is free.
This can then be run using Shell. However, if you want to wait until the zipping has completed (could take some time) do not just use Shell. If you do this, the next line of code will probably run before the zipping has finished. If you want to know how I get around this, post a reply - not too difficult to implement.

Scheduling a job can be done within the operating system - you do not need to look into third party applications to do this, or write your own code to do this - if you are running Windows servers, that is.
On windows2000, in Control Panel, there is a Scheduled Tasks folder. Open this and you can add other jobs (ie your program) and set various options as to when to run.


Simon
 
thank you.

Yes, I would be interested in seeing how you get around the zipping process. Actually, PKZip may be an easier utility to use then WinZip - I have been searching for info on both of them.

Again, thanks for your help.

Jim
 
Instead of using Shell,:
1. Add a module to your project, and place the following code in it:

' ------------------------------------
' Wait for Shelled Process to complete
' ------------------------------------
Option Explicit

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

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

Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long

Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Public Function ExecCmd(ByVal sCmdline As String) As Variant
' --------------------------------------------
' Execute command line and wait for completion
' --------------------------------------------

Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim lReturn As Long

' Initialize the STARTUPINFO structure
start.cb = Len(start)

' Start the shelled application
lReturn = CreateProcessA(0&, sCmdline, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

' Wait for the shelled application to finish
lReturn = WaitForSingleObject(proc.hProcess, INFINITE)
GetExitCodeProcess proc.hProcess, lReturn
CloseHandle proc.hProcess
ExecCmd = lReturn

End Function


2. In your application, instead of calling

Shell("path_and_file_name_of_exe/bat/...")

call

ExecCmd("path_and_file_name_of_exe/bat/...")

Simon
 
thank you for your help, Simon.

bye
Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top