Hi
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.Tutoria l.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.