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,anybo dy can help me ? that 's when remove "\\\\host00 8" , it 's work
well,when i add "\\\\host008",i t's got error !
"Unhandled Exception: System.IO.FileN otFoundExceptio n: Explorer.EXE
at System.Diagnost ics.FileVersion Info.GetVersion Info(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.Manageme nt;
using System.Diagnost ics;
using System.Text.Reg ularExpressions ;
public class QueryProcess02 {
public static void Main(){
ManagementObjec tSearcher searcher = new
ManagementObjec tSearcher("\\\\ host008\\root\\ cimv2","Select * from
Win32_Process") ;
foreach (ManagementObje ct process in searcher.Get())
{
//Console.WriteLi ne("Process Caption: "+ process["Caption"]);
//Console.WriteLi ne("Process Description: "+ process["Descriptio n"]);
string[] s= new String[2];
process.InvokeM ethod("GetOWner ",(object[])s);
string prOwner = s[1]+"\\"+s[0];
if (prOwner.Length ==13)
{//Console.WriteLi ne(prOwner);
string prFullPath = process["ExecutablePath "].ToString();
//Console.WriteLi ne(prFullPath);
//prFullPath = "@"+prFullP ath;
// Console.WriteLi ne("Break Point Test01");
// Console.WriteLi ne(prFullPath);
FileVersionInfo myFileVersionIn fo =
FileVersionInfo .GetVersionInfo (@prFullPath);
// Console.WriteLi ne("Break Point Test02");
//Console.WriteLi ne("CompanyName :" + myFileVersionIn fo.CompanyName) ;
//Console.WriteLi ne("FileVersion :" + myFileVersionIn fo.FileVersion) ;
if (myFileVersionI nfo.CompanyName == null)
{//Console.WriteLi ne("None CompanyName in this Process!");
//Console.WriteLi ne("OriginalFil eName: "+
myFileVersionIn fo.OriginalFile name);
continue;
}
else{
Regex r = new
Regex("(Microso ft|Kingsoft|Sym antec|Oracle|IZ Software|Adobe) .*");
if(!r.IsMatch(m yFileVersionInf o.CompanyName))
{
Console.Write(" CompanyName:" + myFileVersionIn fo.CompanyName) ;
Console.Write(" OriginalFileNam e:" +
myFileVersionIn fo.OriginalFile name);
Console.WriteLi ne("you are using illegal software !");
}
}
}
}
}
}
local Computer, but failed and got the below error when i query remote host
processes,anybo dy can help me ? that 's when remove "\\\\host00 8" , it 's work
well,when i add "\\\\host008",i t's got error !
"Unhandled Exception: System.IO.FileN otFoundExceptio n: Explorer.EXE
at System.Diagnost ics.FileVersion Info.GetVersion Info(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.Manageme nt;
using System.Diagnost ics;
using System.Text.Reg ularExpressions ;
public class QueryProcess02 {
public static void Main(){
ManagementObjec tSearcher searcher = new
ManagementObjec tSearcher("\\\\ host008\\root\\ cimv2","Select * from
Win32_Process") ;
foreach (ManagementObje ct process in searcher.Get())
{
//Console.WriteLi ne("Process Caption: "+ process["Caption"]);
//Console.WriteLi ne("Process Description: "+ process["Descriptio n"]);
string[] s= new String[2];
process.InvokeM ethod("GetOWner ",(object[])s);
string prOwner = s[1]+"\\"+s[0];
if (prOwner.Length ==13)
{//Console.WriteLi ne(prOwner);
string prFullPath = process["ExecutablePath "].ToString();
//Console.WriteLi ne(prFullPath);
//prFullPath = "@"+prFullP ath;
// Console.WriteLi ne("Break Point Test01");
// Console.WriteLi ne(prFullPath);
FileVersionInfo myFileVersionIn fo =
FileVersionInfo .GetVersionInfo (@prFullPath);
// Console.WriteLi ne("Break Point Test02");
//Console.WriteLi ne("CompanyName :" + myFileVersionIn fo.CompanyName) ;
//Console.WriteLi ne("FileVersion :" + myFileVersionIn fo.FileVersion) ;
if (myFileVersionI nfo.CompanyName == null)
{//Console.WriteLi ne("None CompanyName in this Process!");
//Console.WriteLi ne("OriginalFil eName: "+
myFileVersionIn fo.OriginalFile name);
continue;
}
else{
Regex r = new
Regex("(Microso ft|Kingsoft|Sym antec|Oracle|IZ Software|Adobe) .*");
if(!r.IsMatch(m yFileVersionInf o.CompanyName))
{
Console.Write(" CompanyName:" + myFileVersionIn fo.CompanyName) ;
Console.Write(" OriginalFileNam e:" +
myFileVersionIn fo.OriginalFile name);
Console.WriteLi ne("you are using illegal software !");
}
}
}
}
}
}
Comment