Console application checking if .NET installed


B

Brian Stoop

If .NET is not installed my console application pops up "the application
failed to initialize properly" dialog.

Can I programatically tell if .NET is installed, and pre-emp this message
with my own ?

thanks
 
Ad

Advertisements

P

Petros Amiridis

Brian Stoop said:
If .NET is not installed my console application pops up "the application
failed to initialize properly" dialog.
Can I programatically tell if .NET is installed, and pre-emp this message
with my own ?
My guess is that if you wrote that test code as .NET managed one, the
machine should already have .NET installed for that code to be able to run.
I think in order to test if .NET is installed, one should write an external
native application that checks this somehow (maybe looking in the registry,
or trying to run a .NET utility that returns the version of .NET) and
somehow always run that before running the actual .NET console application.
But this is only a guess, maybe I am missing something so don't take what I
said for granted.
 
B

Brian Stoop

Thanks. But I dont wish to have to write a calling app. I am definately
looking for an in-line approach.

B.
 
R

Rene

I always wondered why Microsoft didn’t just add support to the OS to be able
to handle this situation more gracefully.

For example, why can’t the OS somehow intercept the launching call and run
some quick logic to see if the exe requires .Net? If the exe does require
..Net and .Net is not installed then display a better and more informative
message with website links and all… maybe even an option to install the
..Net.

Oh well.
 
L

Lasse Vågsæther Karlsen

Rene said:
I always wondered why Microsoft didn’t just add support to the OS to be able
to handle this situation more gracefully.

For example, why can’t the OS somehow intercept the launching call and run
some quick logic to see if the exe requires .Net? If the exe does require
.Net and .Net is not installed then display a better and more informative
message with website links and all… maybe even an option to install the
.Net.

Oh well.
Consider that the people not installing .NET might very well be some of
the same people that never runs Windows Update, so they would never have
this code that knew how to install .NET in the first place.
 
W

Willy Denoyette [MVP]

Search the archives, I've recently posted a simple VBScript that you can run
in order to detect whether .NET is installed.

Willy.
 
Ad

Advertisements

R

Rene

Consider that the people not installing .NET might very well be some of
the same people that never runs Windows Update, so they would never have
this code that knew how to install .NET in the first place.
I can see your point, but .Net has bee around for a while, if Microsoft
would have started doing something about this issue since the very
beginning, *most* computer today would be able to handle this in a very
graceful way.

Yes I agree that there would always be a computer here or there that would
not be able to handle this, when this happens you will get an email and tell
the user how to fix the problem I guess.
 
B

Brian Stoop

Thanks Willy.

Your VBScript code checks the registry I think. I can check the regisry from
my Console App, but if .NET is not is not installed then the same problem
exists?

Is this Catch 22?

thanks
 
W

Willy Denoyette [MVP]

Brian Stoop said:
Thanks Willy.

Your VBScript code checks the registry I think. I can check the regisry
from my Console App, but if .NET is not is not installed then the same
problem exists?

Is this Catch 22?
Exactly, you can't use a .NET program to check whether .NET is installed.
You need unmanaged code, and the easiest that comes to mind is a simple
script (vbscript, jscript), Windows comes with the scripting engines
installed by default.


Willy.
 
J

Jon Skeet [C# MVP]

Brian Stoop said:
Your VBScript code checks the registry I think. I can check the regisry from
my Console App, but if .NET is not is not installed then the same problem
exists?

Is this Catch 22?
It's catch 22 if you want to check it from managed code, yes - which is
why Willy presented a VBScript answer (which therefore doesn't require
..NET).
 
B

Brian Stoop

Its Catch 22 then. My app uses Managed code, and I dont wish to have 2
applications.

Thanks to everyone, B
 
Ad

Advertisements

W

Willy Denoyette [MVP]

No need to write two applications, say you have a console application
"someapp.exe", then you can simply make a command line script like this:

@rem startapp.cmd
@Echo off
Set Version="HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727"
reg query %version% /v Version >nul 2>nul
if not %errorlevel% == 0 (
Echo No such .Net version: %Version%
goto :end
)
someapp.exe
:end

Willy.
 
Ad

Advertisements

B

Brian Stoop

Thanks, but I need a wrapper free solution.

I appreciate your help, B
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Using "net use" in Console application 3
Console application 2
Console Applications 8
Application and Console??? 3
Console Application 7
Console application 1
console applications 3
Console Application 1

Top