Help on "GetProcessesByName(String processName)"

G

Guest

I use this to know if a program is running; until now all ok but on a pc the
procedure return this error :

System.InvalidOperationException: Impossibile ottenere informazioni sui
processi dal computer remoto. ---> System.ArgumentOutOfRangeException: I
segni di graduazione devono essere compresi tra DateTime.MinValue.Ticks e
DateTime.MaxValue.Ticks.
Nome parametro: ticks
at System.DateTime..ctor(Int64 ticks)
at System.DateTime.Subtract(TimeSpan value)
at System.Diagnostics.NtProcessManager.GetThreadInfo(PERF_OBJECT_TYPE
type, IntPtr instancePtr, PERF_COUNTER_DEFINITION[] counters)
at
System.Diagnostics.NtProcessManager.GetProcessInfos(PerformanceCounterLib
library, Int32 processIndex, Int32 threadIndex, IntPtr dataBlockPtr)
at
System.Diagnostics.NtProcessManager.GetProcessInfos(PerformanceCounterLib
library)
--- Fine dell'analisi dello stack dell'eccezione interna ---
at
System.Diagnostics.NtProcessManager.GetProcessInfos(PerformanceCounterLib
library)
at System.Diagnostics.NtProcessManager.GetProcessInfos(String
machineName, Boolean isRemoteMachine)
at System.Diagnostics.ProcessManager.GetProcessInfos(String machineName)
at System.Diagnostics.Process.GetProcessesByName(String processName,
String machineName)
at System.Diagnostics.Process.GetProcessesByName(String processName)
at GModDoc.Connect.InizializzaMonitor()

Does any one know why?
Thank's for help
 
G

Guest

The code is :

Private Sub InizializzaMonitor()
'
' Verifica se monitor già istanziato
'
Try
Dim localAll As Process() = Process.GetProcessesByName("wrdMon")
If localAll.Length = 0 Then
Dim strLocation As System.String =
System.Reflection.Assembly.GetExecutingAssembly.Location.Substring(0,
System.Reflection.Assembly.GetExecutingAssembly.Location.LastIndexOf("\"))
Process.Start(strLocation & "\wrdMon.exe")
End If
Catch ex As Exception
Err(ex, "InizializzaMonitor - Server Applicazione")
End Try

'
' Carica riferimento a dll Server dati
'
Try
aMon =
CType(Activator.GetObject(GetType(Gaspari.srvAddIn.AppMonitor),
"tcp://localhost:8888/appMonitor"), Gaspari.srvAddIn.AppMonitor)
'aMon = New Gaspari.srvAddIn.AppMonitor
'
' Se utente loggato abilita comandi gaspari
'
DistruggiVarsToolbar()
If aMon.usrLog Then
SetToolBar(tlbMain, "0111111111")

CreaVarsToolbar()

tlbMain.Position = MsoBarPosition.msoBarTop
tlbMain.Visible = True

applicationObject.ScreenRefresh()
End If
Catch ex As Exception
Err(ex, "InizializzaMonitor - Caricamento Dll")
End Try

End Sub


The error is in the line " Dim localAll As Process() =
Process.GetProcessesByName("wrdMon")"

The client has win2K (Sp.??)
Thank for help
 
M

Michael D. Ober

Try the following

Dim wrdMon as Process = Nothing
for each p as process in process.GetProcesses()
if p.Name = "wrdMon" then
wrdMon = p
exit for
end if
next p

if wrdMon is Nothing then
Dim strLocation As System.String =
System.Reflection.Assembly.GetExecutingAssembly.Location.Substring(0,
System.Reflection.Assembly.GetExecutingAssembly.Location.LastIndexOf("\"))
Process.Start(strLocation & "\wrdMon.exe")
End If

I have had similar problems with GetProcessesByName either failing or simply
not finding the process even when I know it's running.

Mike.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top