farsight
asked on
Get OCX version
Using .NET, how can I determine the the version when given some file "XYZ.ocx"?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I added a little driver to your code, and tried it.
It does indeed produce the same results.
Thanks for the effort.
--- driver --- C# ---
unsafe public void Test_GetFileVersion()
{
String[] filenames = {
@"%systemroot%\Notepad.exe ",
@"%systemroot%\comctl32.oc x",
@"%systemroot%\comdlg32.oc x",
@"%systemroot%\mci32.ocx",
@"%systemroot%\MSCOMM32.oc x",
@"%systemroot%\mswinsck.oc x",
@"%systemroot%\richtx32.oc x",
@"%systemroot%\sysinfo.ocx ",
@"%systemroot%\sysmon.ocx" ,
@"noSuchFile.ocx"
};
foreach (String filename in filenames)
{
try
{
// Get the file version for the notepad.
string version = GetFileVersion(filename.Re place("%sy stemroot%" , System.Environment.SystemD irectory)) ;
// Print the file name and version number.
Debug.WriteLine("Filename: " + filename + System.Environment.NewLine +
" Version number: " + version);
}
catch (Exception ex)
{
Debug.WriteLine("File: " + filename + " -- not found.");
}
} // foreach
} // Test_GetFileVersion
--- Output ---
Filename: %systemroot%\Notepad.exe
Version number: 5.00.2140.1
Filename: %systemroot%\comctl32.ocx
Version number: 6.00.8022
Filename: %systemroot%\comdlg32.ocx
Version number: 6.00.8877
Filename: %systemroot%\mci32.ocx
Version number: 6.00.8418
Filename: %systemroot%\MSCOMM32.ocx
Version number: 6.00.8169
Filename: %systemroot%\mswinsck.ocx
Version number: 6.00.8877
Filename: %systemroot%\richtx32.ocx
Version number: 6.00.8877
Filename: %systemroot%\sysinfo.ocx
Version number: 6.00.8877
Filename: %systemroot%\sysmon.ocx
Version number: 5.00.2195.6660
Filename: noSuchFile.ocx
Version number: Cannot get version info size
It does indeed produce the same results.
Thanks for the effort.
--- driver --- C# ---
unsafe public void Test_GetFileVersion()
{
String[] filenames = {
@"%systemroot%\Notepad.exe
@"%systemroot%\comctl32.oc
@"%systemroot%\comdlg32.oc
@"%systemroot%\mci32.ocx",
@"%systemroot%\MSCOMM32.oc
@"%systemroot%\mswinsck.oc
@"%systemroot%\richtx32.oc
@"%systemroot%\sysinfo.ocx
@"%systemroot%\sysmon.ocx"
@"noSuchFile.ocx"
};
foreach (String filename in filenames)
{
try
{
// Get the file version for the notepad.
string version = GetFileVersion(filename.Re
// Print the file name and version number.
Debug.WriteLine("Filename:
" Version number: " + version);
}
catch (Exception ex)
{
Debug.WriteLine("File: " + filename + " -- not found.");
}
} // foreach
} // Test_GetFileVersion
--- Output ---
Filename: %systemroot%\Notepad.exe
Version number: 5.00.2140.1
Filename: %systemroot%\comctl32.ocx
Version number: 6.00.8022
Filename: %systemroot%\comdlg32.ocx
Version number: 6.00.8877
Filename: %systemroot%\mci32.ocx
Version number: 6.00.8418
Filename: %systemroot%\MSCOMM32.ocx
Version number: 6.00.8169
Filename: %systemroot%\mswinsck.ocx
Version number: 6.00.8877
Filename: %systemroot%\richtx32.ocx
Version number: 6.00.8877
Filename: %systemroot%\sysinfo.ocx
Version number: 6.00.8877
Filename: %systemroot%\sysmon.ocx
Version number: 5.00.2195.6660
Filename: noSuchFile.ocx
Version number: Cannot get version info size
ASKER
caner_elci,
Please post a tiny "I answered that question." message at this link, so I can give you those points, too.
https://www.experts-exchange.com/questions/20949611/Get-OCX-Version.html
Please post a tiny "I answered that question." message at this link, so I can give you those points, too.
https://www.experts-exchange.com/questions/20949611/Get-OCX-Version.html
Ok, done.. Have a nice coding..
Caner
Caner
ASKER
---
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDiagnosticsFileVersionInfoClassGetVersionInfoTopic.asp
Here's VB.NET Sample code. I tried to pick OCXes I thought would be on your system. It shows the "Product Version", not the "File Version", at least in cases like comdlg32.ocx.
comdlg32.ocx
File Version: 6.00.88.77
Product Version: 6.00.8877
--- VB.NET ---
Public Shared Sub Test_GetFileVersion()
Dim filenames As String() = New String() { _
"%systemroot%\Notepad.exe"
"%systemroot%\comctl32.ocx
"%systemroot%\comdlg32.ocx
"%systemroot%\mci32.ocx", _
"%systemroot%\MSCOMM32.ocx
"%systemroot%\mswinsck.ocx
"%systemroot%\richtx32.ocx
"%systemroot%\sysinfo.ocx"
"%systemroot%\sysmon.ocx",
"noSuchFile.ocx" _
}
For Each filename As String In filenames
Try
' Get the file version for the notepad.
Dim myFileVersionInfo As FileVersionInfo = FileVersionInfo.GetVersion
filename.Replace("%systemr
' Print the file name and version number.
Debug.WriteLine("Filename:
" File: " & myFileVersionInfo.FileDesc
" Version number: " & myFileVersionInfo.FileVers
Catch
Debug.WriteLine("File: " & filename & " -- not found.")
End Try
Next
End Sub
--- Output ---
Filename: %systemroot%\Notepad.exe
File: Notepad
Version number: 5.00.2140.1
Filename: %systemroot%\comctl32.ocx
File: Windows Common Controls ActiveX Control DLL
Version number: 6.00.8022
Filename: %systemroot%\comdlg32.ocx
File: CMDialog ActiveX Control DLL
Version number: 6.00.8877
Filename: %systemroot%\mci32.ocx
File: MCI OLE Control DLL
Version number: 6.00.8418
Filename: %systemroot%\MSCOMM32.ocx
File: MSComm
Version number: 6.00.8169
Filename: %systemroot%\mswinsck.ocx
File: Microsoft Winsock Control DLL
Version number: 6.00.8877
Filename: %systemroot%\richtx32.ocx
File: RichTx32.OCX
Version number: 6.00.8877
Filename: %systemroot%\sysinfo.ocx
File: SysInfo
Version number: 6.00.8877
Filename: %systemroot%\sysmon.ocx
File: System Monitor Control
Version number: 5.00.2195.6660
File: noSuchFile.ocx -- not found.