G
Guest
I wrote one program which can query processes info., it 's work well in my
local Computer, but failed and got the below error when i query remote host
processes,anybody can help me ? that 's when remove "\\\\host008" , it 's work
well,when i add "\\\\host008",it's got error !
"Unhandled Exception: System.IO.FileNotFoundException: Explorer.EXE
at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
at QueryProcess02.Main()"
/*Wrote by Michael C.,pls. do not modify this code if you are not*/
/*a family in Csharp ! Jan 09 2006 */
using System;
using System.Management;
using System.Diagnostics;
using System.Text.RegularExpressions;
public class QueryProcess02 {
public static void Main(){
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("\\\\host008\\root\\cimv2","Select * from
Win32_Process");
foreach (ManagementObject process in searcher.Get())
{
//Console.WriteLine("Process Caption: "+ process["Caption"]);
//Console.WriteLine("Process Description: "+ process["Description"]);
string[] s= new String[2];
process.InvokeMethod("GetOWner",(object[])s);
string prOwner = s[1]+"\\"+s[0];
if (prOwner.Length ==13)
{//Console.WriteLine(prOwner);
string prFullPath = process["ExecutablePath"].ToString();
//Console.WriteLine(prFullPath);
//prFullPath = "@"+prFullPath;
// Console.WriteLine("Break Point Test01");
// Console.WriteLine(prFullPath);
FileVersionInfo myFileVersionInfo =
FileVersionInfo.GetVersionInfo(@prFullPath);
// Console.WriteLine("Break Point Test02");
//Console.WriteLine("CompanyName:" + myFileVersionInfo.CompanyName);
//Console.WriteLine("FileVersion:" + myFileVersionInfo.FileVersion);
if (myFileVersionInfo.CompanyName == null)
{//Console.WriteLine("None CompanyName in this Process!");
//Console.WriteLine("OriginalFileName: "+
myFileVersionInfo.OriginalFilename);
continue;
}
else{
Regex r = new
Regex("(Microsoft|Kingsoft|Symantec|Oracle|IZSoftware|Adobe).*");
if(!r.IsMatch(myFileVersionInfo.CompanyName))
{
Console.Write("CompanyName:" + myFileVersionInfo.CompanyName);
Console.Write("OriginalFileName:" +
myFileVersionInfo.OriginalFilename);
Console.WriteLine("you are using illegal software !");
}
}
}
}
}
}
local Computer, but failed and got the below error when i query remote host
processes,anybody can help me ? that 's when remove "\\\\host008" , it 's work
well,when i add "\\\\host008",it's got error !
"Unhandled Exception: System.IO.FileNotFoundException: Explorer.EXE
at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
at QueryProcess02.Main()"
/*Wrote by Michael C.,pls. do not modify this code if you are not*/
/*a family in Csharp ! Jan 09 2006 */
using System;
using System.Management;
using System.Diagnostics;
using System.Text.RegularExpressions;
public class QueryProcess02 {
public static void Main(){
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("\\\\host008\\root\\cimv2","Select * from
Win32_Process");
foreach (ManagementObject process in searcher.Get())
{
//Console.WriteLine("Process Caption: "+ process["Caption"]);
//Console.WriteLine("Process Description: "+ process["Description"]);
string[] s= new String[2];
process.InvokeMethod("GetOWner",(object[])s);
string prOwner = s[1]+"\\"+s[0];
if (prOwner.Length ==13)
{//Console.WriteLine(prOwner);
string prFullPath = process["ExecutablePath"].ToString();
//Console.WriteLine(prFullPath);
//prFullPath = "@"+prFullPath;
// Console.WriteLine("Break Point Test01");
// Console.WriteLine(prFullPath);
FileVersionInfo myFileVersionInfo =
FileVersionInfo.GetVersionInfo(@prFullPath);
// Console.WriteLine("Break Point Test02");
//Console.WriteLine("CompanyName:" + myFileVersionInfo.CompanyName);
//Console.WriteLine("FileVersion:" + myFileVersionInfo.FileVersion);
if (myFileVersionInfo.CompanyName == null)
{//Console.WriteLine("None CompanyName in this Process!");
//Console.WriteLine("OriginalFileName: "+
myFileVersionInfo.OriginalFilename);
continue;
}
else{
Regex r = new
Regex("(Microsoft|Kingsoft|Symantec|Oracle|IZSoftware|Adobe).*");
if(!r.IsMatch(myFileVersionInfo.CompanyName))
{
Console.Write("CompanyName:" + myFileVersionInfo.CompanyName);
Console.Write("OriginalFileName:" +
myFileVersionInfo.OriginalFilename);
Console.WriteLine("you are using illegal software !");
}
}
}
}
}
}