I have this piece of code that unpacks a zipfile
shellandwait ("C:\Wzunzip C:\test.zip C:\")
After this process is done I want to delete it with
Kill "C:\test.zip"
The problem is that I can not delete the zipfile because the Wzunzip process won't end. The Shellandwait funtion ensures the unpack line finishes first before resuming next code. I know this works becasue there are a few other command in between these 2 commands wich I could not do if the shellandwait function wouldn't work properly.
So here is the question:
How can I end the Wzunzip.exe process so I can delete that horrible zip file afterwords? Oh, I work with VBA.
Thank you for your time and effort.
Best regards,
Jasper
Last edited by Jasper XAFAX; April 22nd, 2004 at 04:32 AM.
Flying is to throw yourself on the ground and miss
if zip exe has a window (else you will have to enum modules...), you can try:
Code:
Option Explicit
Const WM_CLOSE = &H10
Private theCollWin As Collection
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Sub Main()
Set theCollWin = New Collection
theCollWin.Add "at least partial Name of window"
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sSave As String, Ret As Long
Dim theItem As Variant
Dim Thread_id As Long
Dim ThePid As Long
Ret = GetWindowTextLength(hwnd)
If Ret > 0 Then
sSave = Space(Ret)
GetWindowText hwnd, sSave, Ret + 1
For Each theItem In theCollWin
If InStr(1, sSave, theItem, vbTextCompare) > 0 Then
'close window
SetForegroundWindow hwnd
SendMessage hwnd, WM_CLOSE, 0, 0
' Open App.Path & "\log.txt" For Append As #1
' Print #1, sSave
' Close #1
End If
Next
End If
'continue enumeration
EnumWindowsProc = True
End Function
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Thank you for your time and effort to reply.
I do not know if the code you posted is the code I need because I do not fully understand it. Before I go and study this code (I like to know how al of the code works in my project) I would like to verify if it is code I need.
The app Wzunzip will close after it has done it's job but it will stay active in the background. It is only vissible active in the taskmanager. If I end the proces in the taskmanager I can delete the zip file.
Best regards,
Jasper
Flying is to throw yourself on the ground and miss
I found the problem. The Shellandwait function is causing it. I will have to sort that out. Really strange the function has worked with every app exept this on. Proves that I can't take everything for granted.
Best regards,
Jasper
Flying is to throw yourself on the ground and miss
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Here a way to stop process.
Input process name as you see it via task manager....
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
... do you have the one that uses integers? Change them
all to long...
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Originally posted by Jasper XAFAX
[...]Your the next best thing after canned beer[...]
LOL!
Thanks for kind words
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.