471,327 Members | 2,728 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,327 software developers and data experts.

Post my code for FileNotFoundExecption problem, help !

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|IZSoftw are|Adobe).*");
if(!r.IsMatch(myFileVersionInfo.CompanyName))
{
Console.Write("CompanyName:" + myFileVersionInfo.CompanyName);
Console.Write("OriginalFileName:" +
myFileVersionInfo.OriginalFilename);
Console.WriteLine("you are using illegal software !");

}
}
}

}
}
}
Jan 10 '06 #1
1 1673


"roopeman" <ro******@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
|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|IZSoftw are|Adobe).*");
| if(!r.IsMatch(myFileVersionInfo.CompanyName))
| {
| Console.Write("CompanyName:" +
myFileVersionInfo.CompanyName);
| Console.Write("OriginalFileName:" +
| myFileVersionInfo.OriginalFilename);
| Console.WriteLine("you are using illegal software !");
|
| }
| }
|
|
| }
|
| }
| }
| }
|
|
This can never work.

FileVersionInfo myFileVersionInfo =
FileVersionInfo.GetVersionInfo(@prFullPath);

"@prFullPath" is the local (host008) file path! but your code doesn't run on
host008 so you need the UNC path in your call to GetVersionInfo.

Willy.

Jan 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by WIWA | last post: by
reply views Thread by deacon57 | last post: by
3 posts views Thread by Vic Spainhower | last post: by
7 posts views Thread by php_mysql_beginer911 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.