Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How can I get the location of .Net framework installation files path from a .BAT file.
Actually I have to use "Installutil" from a batch file.

Any kind of help is welcome.
Posted
Comments
Sergey Alexandrovich Kryukov 21-Jan-11 2:12am    
Good question, taking into account there can be several versions of Framework on the same machine, each in separate directory.
I do something like "%windir%\Microsoft.NET\Framework\v4.0.30319" (I manually go there and then figure out where is what) but I don't think this is a good way.

Your v.2.0 will be found there:
%windir%\Microsoft.NET\Framework\v2.0.50727
It will work.

Sorry I cannot give real answer.
Prerak Patel 21-Jan-11 3:40am    
Updated the answer with batch file. Does it help you?

1 solution

Here is a way to do it in .Net.
VB
Dim a As Reflection.Assembly = Reflection.Assembly.LoadFile(filename)
Dim IUPath As String = "%SystemRoot%\Microsoft.net\framework\" & a.ImageRuntimeVersion & "\InstallUtil.exe"


Sorry, I didn't notice batch file. Let me do a bit work and I'll be back to you.

[Edit]
Oh man! Here is your solution. Sorry for misunderstanding your question at first.
You now just have to change the %PROG% or pass it as parameter.

Hope this helps.
And yes, %FIRSTPART%%DOTNETVER%%SECONDPART% gives you the path of InstallUtil.

@echo off

SET PROG="YourServiceHere.exe" 

SET FIRSTPART=%WINDIR%\Microsoft.NET\Framework\v
echo %FIRSTPART%
SET SECONDPART=\InstallUtil.exe
SET DOTNETVER=4.0.30319
echo %FIRSTPART%%DOTNETVER%%SECONDPART%
IF EXIST %FIRSTPART%%DOTNETVER%%SECONDPART% GOTO install 
SET DOTNETVER=3.5 
IF EXIST %FIRSTPART%%DOTNETVER%%SECONDPART% GOTO install 
SET DOTNETVER=3.0 
IF EXIST %FIRSTPART%%DOTNETVER%%SECONDPART% GOTO install 
SET DOTNETVER=2.0.50727 
IF EXIST %FIRSTPART%%DOTNETVER%%SECONDPART% GOTO install 
SET DOTNETVER=1.1.4322 
IF EXIST %FIRSTPART%%DOTNETVER%%SECONDPART% GOTO install 
SET DOTNETVER=1.0.3705 
IF EXIST %FIRSTPART%%DOTNETVER%%SECONDPART% GOTO install 
GOTO fail 
:install 
ECHO Found .NET Framework version %DOTNETVER% 
ECHO Installing service %PROG% 
%FIRSTPART%%DOTNETVER%%SECONDPART% %PROG%
GOTO end 
:fail 
echo FAILURE -- Could not find .NET Framework install :param_error 
:end 
ECHO DONE!!! 
Pause
 
Share this answer
 
v5
Comments
rcman1980 27-Jan-14 8:28am    
InstallUtil.exe does not exist on .net 3, net 3.5 and on .net 1.1.4322.
You need to use the prev version if your code is compiled on version that does not have InstallUtil.exe.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900