From: Chris on
Hi,

I have a managed C++ program that needs to check if the .NET framework v1.1
exists each time it runs. I wish I only had to do this at installation time
but users have removed the framework and encountered a crash and entered
complaints so I have to add the check.

I know how to do this as a seperate utility app that would then launch my
executable but I would like to avoid any additional utility apps or
assemblies. Is there any way to check this from a managed assembly without it
crashing when the .net framework does not exist?

I believe the crash will occur as soon as the managed code is loaded, is
this right? I don't know when this happens though. I tried to add some
unmanaged code before any managed code is called but it still crashes first.

Any help would be greatly appreciated.

Thanks,
Chris

From: Michael Nemtsev [MVP] on
Hello Chris,

why not to check the registry entries for .NET existence?

it's installed into specific hives and can be easily tracked

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


C> To elaborate,
C> When do the managed assemblies get loaded? If I can call unmanaged
C> code before hand I would be able to check it then.


From: Prashant on
As Michael already mentioned, please refer to the below link on registry key
detail
http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;315291

"Michael Nemtsev [MVP]" wrote:

> Hello Chris,
>
> why not to check the registry entries for .NET existence?
>
> it's installed into specific hives and can be easily tracked
>
> ---
> WBR,
> Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
>
> "The greatest danger for most of us is not that our aim is too high and we
> miss it, but that it is too low and we reach it" (c) Michelangelo
>
>
> C> To elaborate,
> C> When do the managed assemblies get loaded? If I can call unmanaged
> C> code before hand I would be able to check it then.
>
>
>
From: Chris on
Thanks for the responses,

Checking if the registry values exist is not a problem, going back to the
original question, the problem is needing to check from a managed project. I
was told that I cannot add any new assemblies to our installation so I need
to know if it is even possible to do. Can I call unmanaged code in a managed
project in a way that the managed code is not loaded until after I check the
registry with unmanaged code? Therefore, the executable will not crash before
the check allowing me to show a dialog if the .net framework does not exist.

Thanks,
Chris

"Prashant" wrote:

> As Michael already mentioned, please refer to the below link on registry key
> detail
> http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;315291
>
> "Michael Nemtsev [MVP]" wrote:
>
> > Hello Chris,
> >
> > why not to check the registry entries for .NET existence?
> >
> > it's installed into specific hives and can be easily tracked
> >
> > ---
> > WBR,
> > Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
> >
> > "The greatest danger for most of us is not that our aim is too high and we
> > miss it, but that it is too low and we reach it" (c) Michelangelo
> >
> >
> > C> To elaborate,
> > C> When do the managed assemblies get loaded? If I can call unmanaged
> > C> code before hand I would be able to check it then.
> >
> >
> >
From: Prashant on
If you have managed executable this is how it works.The operating system
loader checks for managed modules by examining a bit in the common object
file format (COFF) header. The bit being set denotes a managed module. If the
loader detects managed modules, it loads mscoree.dll, and _CorValidateImage
and _CorImageUnloading notify the loader when the managed module images are
loaded and unloaded.
You won't be able to turn off/on the bit in COFF header by running the
managed executable. Its not possible to run Managed Executable without CLR
which in turn need .net assemblies

But you could probably write an executable in unmanaged code to check for
..net framework and display a dialog box if it doesn't exist and if it does
exists you could launch your managed executable from your unmanaged code and
terminate the unmanaged exe.Managed exe will impersonate the calling process
security access token.

If your application is being deployed you could also make use of the
installation script to warn users.


"Chris" wrote:

> Thanks for the responses,
>
> Checking if the registry values exist is not a problem, going back to the
> original question, the problem is needing to check from a managed project. I
> was told that I cannot add any new assemblies to our installation so I need
> to know if it is even possible to do. Can I call unmanaged code in a managed
> project in a way that the managed code is not loaded until after I check the
> registry with unmanaged code? Therefore, the executable will not crash before
> the check allowing me to show a dialog if the .net framework does not exist.
>
> Thanks,
> Chris
>
> "Prashant" wrote:
>
> > As Michael already mentioned, please refer to the below link on registry key
> > detail
> > http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;315291
> >
> > "Michael Nemtsev [MVP]" wrote:
> >
> > > Hello Chris,
> > >
> > > why not to check the registry entries for .NET existence?
> > >
> > > it's installed into specific hives and can be easily tracked
> > >
> > > ---
> > > WBR,
> > > Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
> > >
> > > "The greatest danger for most of us is not that our aim is too high and we
> > > miss it, but that it is too low and we reach it" (c) Michelangelo
> > >
> > >
> > > C> To elaborate,
> > > C> When do the managed assemblies get loaded? If I can call unmanaged
> > > C> code before hand I would be able to check it then.
> > >
> > >
> > >