Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Console application checking if .NET installed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Stoop - 25 Feb 2008 09:33 GMT
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
Petros Amiridis - 25 Feb 2008 11:00 GMT
> 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.
Brian Stoop - 25 Feb 2008 13:29 GMT
Thanks. But I dont wish to have to write a calling app. I am definately
looking for an in-line approach.

B.

>> If .NET is not installed my console application pops up "the application
>> failed to initialize properly" dialog.
[quoted text clipped - 9 lines]
> application. But this is only a guess, maybe I am missing something so
> don't take what I said for granted.
Willy Denoyette [MVP] - 25 Feb 2008 17:08 GMT
Search the archives, I've recently posted a simple VBScript that you can run
in order to detect whether .NET is installed.

Willy.

> Thanks. But I dont wish to have to write a calling app. I am definately
> looking for an in-line approach.
[quoted text clipped - 14 lines]
>> application. But this is only a guess, maybe I am missing something so
>> don't take what I said for granted.
Brian Stoop - 25 Feb 2008 18:36 GMT
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

> Search the archives, I've recently posted a simple VBScript that you can
> run in order to detect whether .NET is installed.
[quoted text clipped - 19 lines]
>>> console application. But this is only a guess, maybe I am missing
>>> something so don't take what I said for granted.
Willy Denoyette [MVP] - 25 Feb 2008 18:46 GMT
> Thanks Willy.
>
[quoted text clipped - 3 lines]
>
> 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.
Brian Stoop - 25 Feb 2008 19:27 GMT
Its Catch 22 then. My app uses Managed code, and I dont wish to have 2
applications.

Thanks to everyone, B

>> Thanks Willy.
>>
[quoted text clipped - 10 lines]
>
> Willy.
Willy Denoyette [MVP] - 25 Feb 2008 20:54 GMT
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.

> Its Catch 22 then. My app uses Managed code, and I dont wish to have 2
> applications.
[quoted text clipped - 15 lines]
>>
>> Willy.
Brian Stoop - 26 Feb 2008 00:44 GMT
Thanks, but I need a wrapper free solution.

I appreciate your help, B

> 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:
[quoted text clipped - 31 lines]
>>>
>>> Willy.
Jon Skeet [C# MVP] - 25 Feb 2008 18:53 GMT
> 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).

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Rene - 25 Feb 2008 14:36 GMT
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.

>> If .NET is not installed my console application pops up "the application
>> failed to initialize properly" dialog.
[quoted text clipped - 9 lines]
> application. But this is only a guess, maybe I am missing something so
> don't take what I said for granted.
Lasse Vågsæther Karlsen - 25 Feb 2008 15:53 GMT
> I always wondered why Microsoft didn’t just add support to the OS to be able
> to handle this situation more gracefully.
[quoted text clipped - 19 lines]
>> application. But this is only a guess, maybe I am missing something so
>> don't take what I said for granted.

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.

Signature

Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3

Rene - 25 Feb 2008 17:16 GMT
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.