news:fa3e99c5-4869-4113...@googlegroups.com...
Anch'io utilizzo InnoSetup, con l'interfaccia piu' intuitiva IsTool, non ho
mai provato a smanettarci e vedro' di implementae questi controlli.
Questo stratagemma e' davvero intelligente, che appunto si rende
fondamentale per non trovare aperti, quindi non sovrascribili, gli accdb
durante reinstallazione/sovrascrittura .
Ma quello che intendevo fare e' questo:
Visto che le istanze rimangono aperte inspiegabilemnte all'uscita delle mie
procedure, e visto che se rimangono li, rubano non poche risorse al sistema,
avevo bisogno di individuare il numero di istanza assegnata al mio
'menu.mdb', affinche' cliccando sul pulsante di uscita, mi 'killasse' tutte
le eventuali istanze 'msaccess.exe' aperte (saltando quella corrente del
menu ovviamente, che da li' a bereve si chiudera' sicuramente: si tratta di
un piccolo mdb e non mi ha mai dato problemi).
pertanto, la routine seguente che mi hai suggerito:
Dim obj As Object
For Each obj In GetObject("winmgmts:").ExecQuery("SELECT * FROM
Win32_Process WHERE Name='msaccess.exe'")
obj.Terminate
Next
End Sub
... mi piacerebe potessi utilizzarla killando tutte le istanze msaccess.exe
diverse da quella corrente, attraverso un normale if.. then else...
Che dici?
Si puo' fare no?
Smanettando sul web ho trovato, anche se in inglese, una routine scritta a
suo tempo da Dev Ashish, che permette di tirar fuori il codice di istanza
del mdb corrente (almeno cosi' ho capito=, ma proprio non mi riesc capirci
qualcosa e come utilizzarla (ammesso che sia il passo giusto??)
eccola di seguito:
'************** Code Start ***************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetClassName Lib "user32" Alias _
"GetClassNameA" (ByVal Hwnd As Long, _
ByVal lpClassname As String, _
ByVal nMaxCount As Long) As Long
Private Declare Function apiGetDesktopWindow Lib "user32" Alias _
"GetDesktopWindow" () As Long
Private Declare Function apiGetWindow Lib "user32" Alias _
"GetWindow" (ByVal Hwnd As Long, _
ByVal wCmd As Long) As Long
Private Declare Function apiGetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal Hwnd As Long, ByVal _
nIndex As Long) As Long
Private Declare Function apiGetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal Hwnd As Long, ByVal _
lpString As String, ByVal aint As Long) As Long
Private Const mcGWCHILD = 5
Private Const mcGWHWNDNEXT = 2
Private Const mcGWLSTYLE = (-16)
Private Const mcWSVISIBLE = &H10000000
Private Const mconMAXLEN = 255
Function fEnumWindows()
Dim lngx As Long, lngLen As Long
Dim lngStyle As Long, strCaption As String
lngx = apiGetDesktopWindow()
'Return the first child to Desktop
lngx = apiGetWindow(lngx, mcGWCHILD)
Do While Not lngx = 0
strCaption = fGetCaption(lngx)
If Len(strCaption) > 0 Then
lngStyle = apiGetWindowLong(lngx, mcGWLSTYLE)
'enum visible windows only
If lngStyle And mcWSVISIBLE Then
Debug.Print "Class = " & fGetClassName(lngx),
Debug.Print "Caption = " & fGetCaption(lngx)
End If
End If
lngx = apiGetWindow(lngx, mcGWHWNDNEXT)
Loop
End Function
Private Function fGetClassName(Hwnd As Long) As String
Dim strBuffer As String
Dim intCount As Integer
strBuffer = String$(mconMAXLEN - 1, 0)
intCount = apiGetClassName(Hwnd, strBuffer, mconMAXLEN)
If intCount > 0 Then
fGetClassName = Left$(strBuffer, intCount)
End If
End Function
Private Function fGetCaption(Hwnd As Long) As String
Dim strBuffer As String
Dim intCount As Integer
strBuffer = String$(mconMAXLEN - 1, 0)
intCount = apiGetWindowText(Hwnd, strBuffer, mconMAXLEN)
If intCount > 0 Then
fGetCaption = Left$(strBuffer, intCount)
End If
End Function