yo hago esto...
declaro las estructuras,apis...
'estructura de shellexecuteinfo
Const SEE_MASK_IDLIST = &H4
Dim slayer as variant 'pid del proceso
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Private Declare Function ShellExecuteEx Lib "shell32.dll" (SEI As SHELLEXECUTEINFO) As Long
funcioncita para pasar valores
Private Sub kill_slayer(FileName As String, OwnerhWnd As Long, comandos As String, mataid As Variant)
Dim SEI As SHELLEXECUTEINFO
Dim r As Long
With SEI
'Set the structure's size
.cbSize = Len(SEI)
'Seet the mask
.fMask = SEE_MASK_IDLIST
'Set the owner window
.hwnd = OwnerhWnd
'Show the properties
.lpVerb = ""
'Set the filename
.lpFile = FileName
.lpParameters = comandos
.lpDirectory = vbNullChar
.nShow = 0
.hInstApp = 0
.lpIDList = mataid
End With
r = ShellExecuteEx(SEI)
End Sub
Private Sub tmrcontrola_Timer()
'controla si existe una ventana de cmd abierta
slayer = BuscaPid("cmd.exe")
If slayer <> 0 Then 'si existe una ventana de cmd
'la cerramos
kill_slayer "cmd.exe", Me.hwnd, "exit ", slayer
End If
End Sub
no pongo todas las declaraciones de esta función...la pille de aqui del foro
'
DEVUELVE EL PID DE UN PROCESO A PARTIR DE SU NOMBRE
Private Function BuscaPid(Nombre As String) As Long
Dim Uno As Long
Dim Info As PROCESSENTRY32
Info.dwSize = Len(Info)
Uno = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
Call Process32First(Uno, Info)
'mientras tenga valor correcto
Do While Process32Next(Uno, Info)
'si coinciden damos el resultado
If lstrcmp(Nombre, Info.szExeFile) = 0 Then
BuscaPid = Info.th32ProcessID
Exit Do
End If
Loop
CloseHandle (Uno)
End Function
pues al ejecutarlo me peta...