Retrieve File version on Remote Server (WMI; C#)

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi

I have not received any reply to this post on the .Net forums so am
posting here in case this involves WMI in addition to .Net languages.

The only file information I need to access for a bunch of files (dlls &

exe) on several remote servers is "file version number". Using the code

below, I appear to be able to access all information (properties)
other than file version - using (System.Management Namespace - WMI).
Can anyone assist me how to access file version. I see that for a local

PC, one can use the System.Diagnositcs.FileVersionInfo class (rather
than simply the FileInfo Class which access most other file
information). This leads me to believe that using the CIM_DataFile
Class as per my code equates to using FileInfo class rather than an
equivalent WMI Class for FileVersionInfo.


I am not permitted to use mapped network drives and therefore I believe

that I cannot use the .Net Directory and FileVersionInfo classes to
interogate files in specific direcories on remote servers (Code Below -

aswell)?


//This is code to use for accessing files on Remote Server
string directoryName =
"D:\\Tutorial\\Microsoft.Sdc.Configuration.Tutorial.Business\\bin\\Debug";

string sql = "ASSOCIATORS OF " +
"{Win32_Directory='" + directoryName + "'} " +
"WHERE " +
"AssocClass=CIM_DirectoryContainsFile " +
"ResultClass=CIM_DataFile " +
"ResultRole=PartComponent " +
"Role=GroupComponent";


string computername = "RemoteTestServer";
string path = "\\root\\cimv2";
ConnectionOptions oConn = new ConnectionOptions();
oConn.Username = "SomeUser";
oConn.Password = "SomePassword";


ManagementScope scope = new System.Management.ManagementScope("\\\\" +
computername + path, oConn);
System.Management.RelatedObjectQuery oQuery = new
System.Management.RelatedObjectQuery(sql);
ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(scope, oQuery);
ManagementObjectCollection oFiles = oSearcher.Get();


foreach(ManagementObject oFile in oFiles)
{
Console.WriteLine("File Caption: " +
Convert.ToString(oFile["Caption"]));
Console.WriteLine("File Version: " +
Convert.ToString(oFile["version"])); //DRATS ALWAYS NO VALUE!!!!!!!!!

Console.WriteLine("Archive: " + Convert.ToString(oFile["Archive"]));
Console.WriteLine("Compressed: " +
Convert.ToString(oFile["Compressed"]));
Console.WriteLine("File Name: " +
Convert.ToString(oFile["FileName"]));
Console.WriteLine("File Extension: " +
Convert.ToString(oFile["Extension"]));
Console.WriteLine("File Size: " +
Convert.ToString(oFile["FileSize"]));
Console.WriteLine("File Type: " +
Convert.ToString(oFile["FileType"]));
Console.WriteLine("Last Modified: " +
Convert.ToString(oFile["LastModified"]));
Console.WriteLine("File Size: " +
Convert.ToString(oFile["FileSize"]));
Console.WriteLine("Name: " + Convert.ToString(oFile["Name"]));
Console.WriteLine("Path: " + Convert.ToString(oFile["Path"]));
Console.WriteLine("Name: " + Convert.ToString(oFile["Name"]));
Console.WriteLine("System: " + Convert.ToString(oFile["System"]));
Console.WriteLine("Manufaturer: " +
Convert.ToString(oFile["Manufacturer"]));



}


//This is code to acces File version on local System
System.Diagnostics.FileVersionInfo flInfoVer =
System.Diagnostics.FileVersionInfo.GetVersionInfo(stringFileName);
version = flInfoVer.FileVersion;

Thanks in advance.

.



Relevant Pages

  • Re: Windows Vista and VBScript
    ... My primary problem right now is attaching to remote servers via wmi. ...
    (microsoft.public.scripting.vbscript)
  • Re: Script to Remote Monitor
    ... localhost, it keeps saying unable to connect to WMI for the remotes. ... AFAIK you won't be able to connect to remote servers via WMI from the back ... site _or_ you pass credentials to the back end to do a WMI ConnectServer ...
    (microsoft.public.scripting.wsh)
  • How to access files version numbers on remote servers -WMI, .Net
    ... exe) on several remote servers is "file version number". ... ManagementObjectSearcher oSearcher = new ... ManagementObjectSearcher(scope, oQuery); ... ManagementObjectCollection oFiles = oSearcher.Get; ...
    (microsoft.public.dotnet.general)