vorrei sapere come verificare tramite VB e un processo è attivo o meno, in particolar modo vorrei che se il processo preso in questione non è attivo compia delle operazioni mentre se è attivo ne compia delle altre. Qualcuno sa dirmi come fare?



Imports System
Imports System.Diagnostics
Imports System.ComponentModel
Namespace MyProcessSample
_
'/ <summary>
'/ Shell for the sample.
'/ </summary>
Class MyProcess
Sub BindToRunningProcesses()
' Get the current process.
Dim currentProcess As Process = Process.GetCurrentProcess()
' Get all instances of Notepad running on the local
' computer.
Dim localByName As Process() = Process.GetProcessesByName("notepad")
' Get all instances of Notepad running on the specifiec
' computer.
' 1. Using the computer alias (do not precede with "\\").
Dim remoteByName As Process() = Process.GetProcessesByName("notepad", "myComputer")
' 2. Using an IP address to specify the machineName parameter.
Dim ipByName As Process() = Process.GetProcessesByName("notepad", "169.0.0.0")
' Get all processes running on the local computer.
Dim localAll As Process() = Process.GetProcesses()
' Get all processes running on the remote computer.
Dim remoteAll As Process() = Process.GetProcesses("myComputer")
' Get a process on the local computer, using the process id.
Dim localById As Process = Process.GetProcessById(1234)
' Get a process on a remote computer, using the process id.
Dim remoteById As Process = Process.GetProcessById(2345, "myComputer")
End Sub 'BindToRunningProcesses
Shared Sub Main()
Dim myProcess As New MyProcess()
myProcess.BindToRunningProcesses()
End Sub 'Main
End Class 'MyProcess
End Namespace 'MyProcessSample
![Triste [V]](http://www.megalab.it/forum/images/smilies/sad.gif)
Imports System
Imports System.Diagnostics
Imports System.ComponentModel

Dim ListaProcessi() As Process = Process.GetProcessesByName("notepad")If ListaProcessi.Count > 0 Then
Textbox1.text = "In Esecuzione"
Else
Textbox1.text = "Non in Esecuzione"
End If

M@ttia ha scritto:I vari Imports credo fossero necessari per l'esempio completo sopra ma penso che anche lasciandoli via vada comunque

![Approvazione [^]](http://www.megalab.it/forum/images/smilies/Oh-yea.gif)

M@ttia ha scritto:Poniamo l'esempio di voler verificare se il blocco note (notepad) è in esecuzione. Con:
- Codice: Seleziona tutto
Dim ListaProcessi() As Process = Process.GetProcessesByName("notepad")
ti crei un array ListaProcessi contenente tutte le istanze di "notepad" aperte in quel momento (che possono essere 0, 1 o più di una magari). Se ti basta sapere se almeno un'istanza di notepad è aperta, allora farai:
- Codice: Seleziona tutto
If ListaProcessi.Count > 0 Then
Textbox1.text = "In Esecuzione"
Else
Textbox1.text = "Non in Esecuzione"
End If
I vari Imports credo fossero necessari per l'esempio completo sopra ma penso che anche lasciandoli via vada comunque
Grazie mille funziona
Andy94 ha scritto:
Count non è un membro di System.Array. Per ottenere la lunghezza di un array come ListaProcessi bisogna utilizzare GetLength.
Tutto il resto rimane uguale.

Visitano il forum: Nessuno e 12 ospiti
megalab.it: testata telematica quotidiana registrata al Tribunale di Cosenza n. 22/09 del 13.08.2009, editore Master New Media S.r.l.; © Copyright 2008 Master New Media S.r.l. a socio unico - P.I. 02947530784. GRUPPO EDIZIONI MASTER Spa Tutti i diritti sono riservati. Per la pubblicità: Master Advertising