I'm trying to write a batch file that installs a windows service using installutil.exe. I would like to use the installutil.exe that is in the latest version of the .Net Framework (located in C:\Windows\Microsoft.NET\Framework\v4.0.30319 on my machine).
Is there an easy way to change the directory in the command line to the latest .NET Framework directory?
For example, I know using cd %WINDIR% will give me C:\Windows. What would I type to get to the latest .Net Framework Directory?
Using Reed Copseys advice about inspecting the registry I found a sample on another post about how to read the registry from a batch file.
Here is my batch file that finds the install directory for the .Net 4 Framework and installs my service:
@SET INSTALLUTILDIR=
@for /F "tokens=1,2*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" /v "InstallPath"') DO (
if "%%i"=="InstallPath" (
SET "INSTALLUTILDIR=%%k"
)
)
%INSTALLUTILDIR%\installutil MyService.exe
And here is the link where you can find the registry key for the specific version of the framework you are looking for: http://msdn.microsoft.com/en-us/kb/kbarticle.aspx?id=318785
There is no environment variable you can use as a "standard" replacement like that. The way most installers do it is by inspecting the registry for the Framework installation path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With