Forum Discussion

jackson_1's avatar
jackson_1
Frequent Contributor
14 years ago

cannot get the file version correctly in windows xp

hi all,



    i met a troubsome thing in my project, i create a routine to get the version of the specified execution file likes below, but i find it works well in windows 7 os and get empty value in windows xp, anybody know why does it this?



function GetBuildVersion(AdhocBuild: string): string;


var

    FileObj: OleVariant;

   

begin

    FileObj: = Sys.OleObject['Scripting.FileSystemObject'];        

    Result: = VarToStr(FileObj.GetFileVersion(AdhocBuild));   

            

end;



===================================

and i use another way to test it in windows xp,get the 'FileFullVersion'  unknown name error message when run it, anyone meet this same error?


function GetBuildVersion(AdhocBuild: string): string;


var

    FileObj,VerInfo: OleVariant;

   

begin

    Result: = aqFileSystem.GetFileInfo(AdhocBuild).VersionInfo.FileFullVersion;          

            

end;



anyone can help me?

 

thanks depth!!!


  • Hello Du,



    I have tested your code and it works correctly for the Notepad.exe file in Windows XP. The problem does not look to be related to TestComplete. As the MSDN Library states,




    The GetFileVersion method returns a zero-length string ("") if pathspec does not end with the named component.


    The GetFileVersion method works only on the provided path string. It does not attempt to resolve the path, nor does it check for the existence of the specified path.






    So, please check:


    - whether the path is valid and refers to an existing file. 


    - whether the file contains valid version info.



    If this does not help, please send us the "problematic" file via the Contact Support Form.
  • jackson_1's avatar
    jackson_1
    Frequent Contributor
    hi David,



    thanks  for your replay.



    it looks like very interesting. the script work well on Windows 7. but on Windows XP will can't get the file version correctly. i dont know what's wrong with this. can you help?



    Thanks very much!

  • Hello Du,



    Please check whether the script works correctly on the Windows XP system with the Notepad.exe file and let me know about your results. If the problem is reproduced only with your specific binary file, please send it to us via the Contact Support Form as I asked you in my previous post.







  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Du,



    [DelphiScript]

    VerInfo := aqFileSystem.GetFileInfo(TestedApps.<yourAppName>.FullFileName).VersionInfo;



    Does it work in your case?

  • Hello Du,





    We have reproduced the problem when it is impossible to obtain the version of a large executable in Windows XP using either the aqFileSystem object or the Scripting.FileSystemObject object. I have registered the problem in our database. We are investigating whether it is possible to overcome this restriction, and we will let you know our results as soon as we have some.
  • Hello Du,



    We have found the following workaround. Please let us know how it works for you.



    procedure Test;


    var path, oWMI, oFile;


    begin


      path := 'C:\\Test\\large_file.exe';  // note double backslashes!


      oWMI := Sys.OleObject('WbemScripting.SWbemLocator').ConnectServer;


      oFile := oWMI.Get('CIM_DataFile.Name="' + path + '"');


      Log.Message(oFile.Version);


    end;


  • jackson_1's avatar
    jackson_1
    Frequent Contributor
    Hi Alex,



    Thanks very much for your help. it work well in my project use your script.



    but a small question when i get the version of the file under the Net Folder(Eg.\\ZHUFOLDER\Temp\test.exe).  i get the "DelphiScript runtime error,SWbemServicesEx" error message. what's wrong with this. can you help again?



    Thanks again.
  • Hello Du,



    The cause of the error is that the CIM_DataFile WMI class does not support network paths. I recommend that you create a mapped network drive for the folder that contains the file. In this case, you will be able to use a local path in the script.



    How to create a mapped network drive, please read here.



    Does this work for you?
  • jackson_1's avatar
    jackson_1
    Frequent Contributor
    Hi Alex,



    Yes. it works well in my project now.



    Thanks Again.