Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command Line Variable for .NET Framework

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?

like image 674
TrueEddie Avatar asked Jan 09 '14 19:01

TrueEddie


2 Answers

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

like image 119
TrueEddie Avatar answered Oct 13 '22 20:10

TrueEddie


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.

like image 29
Reed Copsey Avatar answered Oct 13 '22 20:10

Reed Copsey