I have the following code :
Imports System.Management Module Module1 Private MicrosoftProcs As New List(Of String) Private Sub FindMicrosoftProcs() Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_Process") For Each p2 As ManagementObject In searcher.Get() If p2("Name") <> "System" Or p2("Name") <> "System Idle Process" Or p2("Name") <> Process.GetCurrentProcess.ProcessName & ".exe" Then Dim x As String = p2("ExecutablePath") If Not x Is Nothing Then If x.Length > 2 Then Dim fvi As System.Diagnostics.FileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(p2("ExecutablePath").ToString) Dim sDescription As String = fvi.CompanyName & "/" & fvi.LegalCopyright & "/" & fvi.LegalTrademarks & "/" & fvi.ProductName & "/" & fvi.FileDescription & "/" If sDescription.ToLower.Contains("microsoft") Then MicrosoftProcs.Add(p2("ExecutablePath")) Debug.WriteLine("Microsoft process : " & p2("ExecutablePath")) End If End If End If End If Next End Sub End Module
I am working on 64bit Windows but the code is compiled for 32bit Windows (for compatibility). If I run the code compiled for 64bit , i have not problems with the code, but if I run it compiled for 32bit I get the FileNotFoundException :
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.dll System.IO.FileNotFoundException: C:\Windows\system32\csrss.exe at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName) at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\Maximus\Documents\Visual Studio 2010\Projects\rupe\rupe\Form1.vb:line 81
And I don't know how to fix it. Can you help me please ? Thanks in advance.
If p2("Name") "System" Or p2("Name") "System Idle Process" Or p2("Name") Process.GetCurrentProcess.ProcessName & ".exe" Then
– Joe UhrenIf p2("Name") = "System" Or p2("Name") = "System Idle Process" Or p2("Name") = Process.GetCurrentProcess.ProcessName & ".exe" Then
otherwise it wouldn't comile. – Joe Uhren<>
in that code, then your logic is wrong. TheOr
should beAndAlso
instead. – Chris Dunaway