Here is a way to do it in .Net.
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