Post my code for FileNotFoundExecption problem, help !

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • roopeman

    #1

    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,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 !");

    }
    }


    }

    }
    }
    }


  • Willy Denoyette [MVP]

    #2
    Re: Post my code for FileNotFoundExe cption problem, help !



    "roopeman" <roopeman@discu ssions.microsof t.com> wrote in message
    news:F7959FE0-C997-4A8E-919F-6007839C8A3B@mi crosoft.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,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 !");
    |
    | }
    | }
    |
    |
    | }
    |
    | }
    | }
    | }
    |
    |
    This can never work.

    FileVersionInfo myFileVersionIn fo =
    FileVersionInfo .GetVersionInfo (@prFullPath);

    "@prFullPat h" 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.



    Comment

    Working...