473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Version of Framework

Hi All,

I have the both of framework (1.1 and 2.0) in my pc. How can i identify the
version of framework an application uses ?
tk´s
Jul 4 '06 #1
4 1845
I forgot but this is about "windows application"

"William Leme" wrote:
Hi All,

I have the both of framework (1.1 and 2.0) in my pc. How can i identify the
version of framework an application uses ?
tk´s
Jul 4 '06 #2
Hello William,

I'm not sure if this is availabe via managed code.
The version of the CLR used when the assembly was built is recorded into
assembly during the compiling.
Thus you need to analyze PE header to get this info. This version string
is located in a 16 bytes after the start of the metadata section
See samples below describing how to get this info
// The CLR metadata header is currently 16 bytes.
#define CLR_MD_HEADER_SIZE 16

DWORD ConvertVirtualAddressToOffset(IMAGE_NT_HEADERS *pNtHeader, DWORD virtualAddress)
{
// find the right section
ULONG i;
PIMAGE_SECTION_HEADER pNtSection;
pNtSection = IMAGE_FIRST_SECTION( pNtHeader );
for (i=0; i<pNtHeader->FileHeader.NumberOfSections; i++)
{
if (virtualAddress >= pNtSection->VirtualAddress &&
virtualAddress < pNtSection->VirtualAddress + pNtSection->SizeOfRawData)
break;

++pNtSection;
}

// compute offset from va
assert(pNtSection);
return ((virtualAddress - pNtSection->VirtualAddress) + pNtSection->PointerToRawData);
}

int _tmain(int argc, _TCHAR* argv[])
{
if (argc < 2)
{
printf("Usage: ClrVersion <Exe or Dll name>\n");
return 0;
}

// error checking to determine if the file is in fact a PE is omitted.....

// open the file
HANDLE hFile = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
assert (hFile != INVALID_HANDLE_VALUE);

// Create a file mapping object
HANDLE hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0,
NULL);
assert (hFile != INVALID_HANDLE_VALUE);

// Map the file
PBYTE pbFile = NULL;
pbFile = (PBYTE) MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
assert(pbFile);

// Get the nt header
IMAGE_DOS_HEADER *pDosHeader = (IMAGE_DOS_HEADER*)pbFile;
IMAGE_NT_HEADERS *pNtHeader = (IMAGE_NT_HEADERS*)(pbFile + pDosHeader->e_lfanew);

// Skip to the clr header. If the directory entry for clr isn't filled in
we know
// this isn't a managed PE
DWORD dwClrHeaderVA = pNtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
if (dwClrHeaderVA == 0)
{
printf("%s is not a managed executable file\n", argv[1]);
return 0;
}

DWORD dwClrHeaderOffset = ConvertVirtualAddressToOffset(pNtHeader, dwClrHeaderVA);
IMAGE_COR20_HEADER* pCorHeader = (IMAGE_COR20_HEADER*) (pbFile + dwClrHeaderOffset);
// The version string is stored near the beginning of the metadata section.
Skip to
// the metadata and find the string.
DWORD dwClrMDVA = pCorHeader->MetaData.VirtualAddress;
DWORD dwClrMDOffset = ConvertVirtualAddressToOffset(pNtHeader, dwClrMDVA);

LPBYTE pMetaData = (pbFile + dwClrMDOffset);

// the string starts 16 bytes from the beginning of the metadata section
LPCSTR pVersion = (LPCSTR) (pMetaData + CLR_MD_HEADER_SIZE);

printf("%s was built with %s of the CLR\n", argv[1], pVersion);

// clean up
UnmapViewOfFile(pbFile);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return 0;
}

WLI forgot but this is about "windows application"
WL>
WL"William Leme" wrote:
WL>
>Hi All,

I have the both of framework (1.1 and 2.0) in my pc. How can i
identify the version of framework an application uses ?

tk´s
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jul 4 '06 #3
>I'm not sure if this is availabe via managed code.

It is, via Assembly.ImageRuntimeVersion. But the version it was built
against isn't necessarily the version that actually loads. You can use
the Clrver.exe tool in the .NET 2.0 SDK to find out which version is
loaded for a specific process. If it's from within your own managed
application you want to check, use Environment.Version.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 4 '06 #4
Hello Mattias,
>I'm not sure if this is availabe via managed code.
MSIt is, via Assembly.ImageRuntimeVersion.

Yep, thanks for the note
MSBut the version it was
MSbuilt against isn't necessarily the version that actually loads. You
MScan use the Clrver.exe tool in the .NET 2.0 SDK to find out which
MSversion is loaded for a specific process. If it's from within your
MSown managed application you want to check, use Environment.Version.

Sure, version policy could redirect us to any version.

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jul 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: angelag | last post by:
I am currently taking a college course in Visual Basic.Net and I am a beginner. I bought Visual Studio.Net 2003 to do my homework at home. I built my first project and e-mailed it to myself at...
2
by: j.b.messina | last post by:
This has not yet been published by Microsoft. It will be published within the next few weeks, mainly because I asked them to. I felt this was information badly needed, and I think this is the...
4
by: Earl T | last post by:
When I try to get the netscape version for version 7, I get the HttpBrowserCapabilities class returning the version as 5 and not 7. (see code and output below) CODE HttpBrowserCapabilities...
2
by: Reggie | last post by:
Hi and TIA! Little confused. I'm running WXP Pro (SP2). If I look at Control Panel/Admin Tools it shows the following: Microsoft .NET Framework 1.1 Configuration Microsoft .NET Framework 1.1...
1
by: Harry Simpson | last post by:
I know I drilled down into the Windows folder\Microsoft.net\Framework\v1.1.4322 folder and looked at the version of Mscorcfg.dll to get the SP level from the version number: Mine shows...
3
by: Shadow Lynx | last post by:
At the bottom of the default Error page that appears when Unhandled Exceptions occur, what exactly is the difference between the "Microsoft ..Net Framework Version" and the "ASP.NET Version"? I...
0
by: Felix | last post by:
Ok, I've had this issues since yesterday and I cannot figure out what's causing it. Basically, I have a Visual Studio 2005 Web Service. The service runs completely find on my local development...
29
by: =?Utf-8?B?SGVybWF3aWg=?= | last post by:
Hello, Please anybody help me. I have only a little experience with web development. I created simple project using ASP NET 2.0 (VS 2005) It works fine on local computer. When I tried to run...
5
by: jroozee | last post by:
I am developing in VS '03. I have all of the current framework versions installed on my PC, 1.1, 2.0, and 3.0. How can I make sure the code I am developing in is using the 3.0 framework version?...
11
by: pg | last post by:
My old HD crashes, so I had to do a total re-install. After installer XP, I went to the Micrsoft Update site to get all the update. After 5 hours or so ... the update cycle started looping. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.