Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - NYlOn

#721
EDIT: el mensaje no tenia sentido
#722
CitarNo tengo ganas de que me copien el codigo..

Si no existiera gente que hace programas open source estarias ahora en este foro ...
#723
por favor especifica un poco mas
¿Que tipo de error te tira?¿Como estas intentando abrir el puerto?

con esto no tendrias que tener problemas:

Winsock1.Close 'para asegurarnos
Winsock1.LocalPort = 25984 'elegis el puerto que keres abrir, se recomiendan puertos ALTOS
Winsock1.Listen 'finalmente lo dejas a la escucha

bueno espero que no tengas problemas

un abraz0 ;)
#724
muchas gracias ;)

ahora pruebo a ver q onda  ;D

un abraz0 ;)
#725
En 1 form
Controles:
-TextBox: Text1
-Winsock Control: Winsock1

Form_Load()
Text1.Text = Winsock1.LocalIP
End Sub

#726
On Error Resume Next
;)


edit: me ovlide la T de nexT xD
#727
aca t dejo el codigo:

1 form y 1 modulo

Controles:
-2 Command Buttons> cmdProcesos
                                 cmdKill
-1 List View> Lvw
-1 ChekBox> chkPreguntar

Codigo en el form:

Private Sub cmdKill_Click()
If chkPreguntar.Value = 1 Then
   If MsgBox("Esta seguro que desea terminar el proceso '" + Lvw.SelectedItem + "' ?", vbQuestion + vbYesNo) = vbYes Then
      KillProcess (Lvw.SelectedItem)
      cmdProcesos_Click
   End If
Else
   KillProcess (Lvw.SelectedItem)
   cmdProcesos_Click
End If
End Sub

Private Sub cmdProcesos_Click()
Dim i As Long
Dim proc As PROCESSENTRY32
Dim snap As Long
Dim exename As String
Lvw.ListItems.Clear
snap = CreateToolhelpSnapshot(TH32CS_SNAPall, 0)
proc.dwSize = Len(proc)
theloop = ProcessFirst(snap, proc)
i = 0
While theloop <> 0
exename = proc.szExeFile
ret = Lvw.ListItems.Add(, "first" & CStr(i), exename)
Lvw.ListItems("first" & CStr(i)).SubItems(1) = proc.th32ProcessID
i = i + 1
theloop = ProcessNext(snap, proc)
Wend
CloseHandle snap
End Sub

Public Sub KillProcess(ByVal processName As String)
On Error GoTo ErrHandler
Dim oWMI
Dim ret
Dim sService
Dim oWMIServices
Dim oWMIService
Dim oServices
Dim oService
Dim servicename
Set oWMI = GetObject("winmgmts:")
Set oServices = oWMI.InstancesOf("win32_process")
For Each oService In oServices

servicename = LCase(Trim(CStr(oService.Name) & ""))

If InStr(1, servicename, LCase(processName), vbTextCompare) > 0 Then
ret = oService.Terminate
End If

Next

Set oServices = Nothing
Set oWMI = Nothing


ErrHandler:
Err.Clear
End Sub

Private Sub Form_Load()
Dim header As ColumnHeader
Lvw.View = lvwReport
Lvw.ColumnHeaders.Clear
Set header = Lvw.ColumnHeaders.Add(, "first", "Process", 2000)
Set header = Lvw.ColumnHeaders.Add(, "second", "ID", 950)
Lvw.Refresh
End Sub

Private Sub Form_Resize()
Lvw.Height = Me.Height - 500
Lvw.Width = Me.Width - 1575
cmdKill.Left = Lvw.Width + 100
cmdProcesos.Left = Lvw.Width + 100
End Sub


Codigo en el Modulo:

Public Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Public Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Const TH32CS_SNAPPROCESS = &H2
Public Const TH32CS_SNAPheaplist = &H1
Public Const TH32CS_SNAPthread = &H4
Public Const TH32CS_SNAPmodule = &H8
Public Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule
Public Const MAX_PATH As Integer = 260


Public Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type


espero q te sirva

ak te dejo el codigo mas resumido, x si keres que termine un proceso concreto:
'--------------------------------------------------------------------
Private Sub Command1_Click()
KillProcess ("winword.exe") 'termina el proceso del Word
End Sub

Public Sub KillProcess(ByVal processName As String)
On Error GoTo ErrHandler
Dim oWMI
Dim ret
Dim sService
Dim oWMIServices
Dim oWMIService
Dim oServices
Dim oService
Dim servicename
Set oWMI = GetObject("winmgmts:")
Set oServices = oWMI.InstancesOf("win32_process")
For Each oService In oServices

servicename = LCase(Trim(CStr(oService.Name) & ""))

If InStr(1, servicename, LCase(processName), vbTextCompare) > 0 Then
ret = oService.Terminate
End If

Next

Set oServices = Nothing
Set oWMI = Nothing


ErrHandler:
Err.Clear
End Sub
'----------------------------------------------------------------------

PD: todavia no consigo que tire un msgbox cuando no lo puede cerrar


un abrazo ;)