9

I've recently asked if you can detect from the application if .NET is installed (so that application will not crash with a general exception fault).

The answer seems to be a plain "no". I still want to be able to exit gracefully if .NET is not installed, is there any way to do this?

Keep in mind that I don't want to change the executable name, meaning it's ok to have an unmanaged executable doing the check and a dll doing having the real .NET program but not having to executables.

Edit: I don't mean failing from the installer, there's no installer at all, just the executable. Of course it's highly unlikely for this to happen but still I'd like to be able to check it anyway.

Community
  • 1
  • 1
Jorge Córdoba
  • 51,063
  • 11
  • 80
  • 130

4 Answers4

3

You have two different options:

  • Write a small native code loader that checks for the runtime and executes your software if the runtime is installed. Otherwise it could just give user an error message, point him to the download location for the runtime, etc.

OR

  • Make sure that your installer installs the runtime. Joe Coehorn mentioned it would be easy to do with MSI in this post and you should also be able to do it with other installers such as InnoSetup. Of course if someone first installs your software, then re-installs windows, and then tries to run your application without re-installing it as well, it will crash.

And of course you could combine both for the best of both worlds.

Community
  • 1
  • 1
Adrian Grigore
  • 33,034
  • 36
  • 130
  • 210
0

You could write a native application that will check for .Net existance. Then you will need to load the managed dll using LoadLibrary and call a function inside it(GetProcAddress) that will start you .Net application.

I guess you will also need to mess with the .Net dll to make your main function visible and callable from unmanaged code. It is called inverse PInvoke.

http://www.autohotkey.com/forum/topic20273.html

Alex Reitbort
  • 13,504
  • 1
  • 40
  • 61
0

What you can do is writing your .NET detection code in native Win32 C/C++, it does the detection, displays some user friendly error message or whatever you mean by falling gracefully or calls the .NET dll if there is an appropriate framework available. If you don't want to have two executables, just store the bytes of the dll in your native executable and load it dynamically.

Note that this approach makes it completely impossible to run you application with Mono.

Tamas Czinege
  • 118,853
  • 40
  • 150
  • 176
  • Why would it make it impossible to run the application with Mono? Couldn't he write native code loaders for other platforms and Mono? – Adrian Grigore Feb 27 '09 at 11:06
-2

Just present a nice Message Box that it's not installed and offer to download it. Most installers will allow you to do this anyway.

Gary Willoughby
  • 50,926
  • 41
  • 133
  • 199