Microsoft .NET Framework

(imported topic written by ncfb)

Hey,

Can someone help me write a fixlet in detectin Microsoft .NET framework on the workstations. I have 2000 and XP machines. Is what I would like to have is a retrieved property that will come back with a version number and if it is not installed on the machine. To say that it isnt installed. I have found a file on the machine that I think will give me the appropriate information. So I am looking for something like this, this doesnt work.

exists version of file “netfxsbs10.exe” of folder “c:winnt\microsoft.NET\Framework” OR exists version of file “netfxsbs10.exe” of folder “c:\windows\microsoft.NET\Framework” else “Not Installed”

(imported comment written by brolly3391)

First, here is the way I would do it:

q: if (exists key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework” whose (exists value “InstallRoot” whose (exists folder (it as string) whose (exists file “netfxsbs10.exe” of it)) of it) of registry) then (version of file “netfxsbs10.exe” of folder (value “InstallRoot” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework” of registry as string) )as string else (“Not Installed”)

A: 2.0.50727.42

T: 3.307 ms

I: singular string

Lets see if we can make your approach work.

First, we cannot use ELSE outside of an IF THEN ELSE construct. Let’s take the windows XP possibilities on first:

q: version of file “netfxsbs10.exe” of folder “C:\WINDOWS\Microsoft.NET\Framework”

A: 2.0.50727.42

T: 2.156 ms

I: singular version

seems good. But what happens if we take the Windows 2000 possibility on the same XP test box?

q: version of file “netfxsbs10.exe” of folder “C:\WINNT\Microsoft.NET\Framework”

E: Singular expression refers to nonexistent object.

An error result for any part of our relevance is bad because it will error out the entire statement even if it would otherwise be true. So we need to make sure that the folder and file both exist before we pull the file version. The folder is easy:

q: exists folder “C:\WINNT\Microsoft.NET\Framework”

A: False

but the file + folder is not as easy:

q: exists file “netfxsbs10.exe” of folder “C:\WINNT\Microsoft.NET\Framework”

E: Singular expression refers to nonexistent object.

It’s best to approach this with a WHOSE IT clause.

q: exists folder “C:\WINNT\Microsoft.NET\Framework” whose ( exists file “netfxsbs10.exe” of it )

A: False

Now we don’t get that error which was going to trip us up later. It always seems to me like these things are built upside-down… So now we put our test for existence into the IF THEN ELSE and get:

q: if (exists folder “C:\WINNT\Microsoft.NET\Framework” whose ( exists file “netfxsbs10.exe” of it )) then (version of file “netfxsbs10.exe” of folder “C:\WINNT\Microsoft.NET\Framework”) else “Not Installed”

E: Incompatible types.

we are so close… IF THEN ELSE wants the return types of the THEN and the ELSE to match, so we should turn the version into a string to match the string “Not Installed”. We can do that using the cast AS STRING.

q: if (exists folder “C:\WINNT\Microsoft.NET\Framework” whose ( exists file “netfxsbs10.exe” of it )) then (version of file “netfxsbs10.exe” of folder “C:\WINNT\Microsoft.NET\Framework”) as string else “Not Installed”

A: Not Installed

T: 0.503 ms

I: singular string

and the Windows XP half:

q: if (exists folder “C:\WINDOWS\Microsoft.NET\Framework” whose ( exists file “netfxsbs10.exe” of it )) then (version of file “netfxsbs10.exe” of folder “C:\WINDOWS\Microsoft.NET\Framework”) as string else “Not Installed”

A: 2.0.50727.42

T: 2.900 ms

I: singular string

Victory! No more error when we run the Windows 2000 version on a Windows XP box. Now we can stick them together in a nested IF THEN ELSE. This would be your final relevance using the method you put forward in your post.

q: if (exists folder “C:\WINDOWS\Microsoft.NET\Framework” whose ( exists file “netfxsbs10.exe” of it )) then (version of file “netfxsbs10.exe” of folder “C:\WINDOWS\Microsoft.NET\Framework”) as string else ( if (exists folder “C:\WINNT\Microsoft.NET\Framework” whose ( exists file “netfxsbs10.exe” of it )) then (version of file “netfxsbs10.exe” of folder “C:\WINNT\Microsoft.NET\Framework”) as string else “Not Installed” )

A: 2.0.50727.42

T: 2.875 ms

I: singular string

Frequently, installed runtimes and applications will have a pointer in a fixed location in the Registry that tells you the folder where it is installed. I like to use those registry pointers instead of hard coded folder names whenever possible when querying the information for those applications. It takes care of the “What if the user somehow installed the application in a non-default location?” question. Of course we then need to test for the existence of the registry key as well as the existence of the folder and file before using it or else we risk getting that “E: Singular expression refers to nonexistent object” error from before. The nice thing is that we don’t have to write 2 different versions and paste them together in a nested IF THEN ELSE. The not so nice thing is we get really deep on the nested WHOSE IF clauses as we check for the existence of each item along the way. (see the statement at the top of page)

There are lots of good examples of how the BigFix pros do this in the existing fixlets, especially the MS0x-xxx series.

(imported comment written by jessewk)

brolly33

q: if (exists folder “C:\WINDOWS\Microsoft.NET\Framework” whose ( exists file “netfxsbs10.exe” of it )) then (version of file “netfxsbs10.exe” of folder “C:\WINDOWS\Microsoft.NET\Framework”) as string else ( if (exists folder “C:\WINNT\Microsoft.NET\Framework” whose ( exists file “netfxsbs10.exe” of it )) then (version of file “netfxsbs10.exe” of folder “C:\WINNT\Microsoft.NET\Framework”) as string else “Not Installed” )

You can make this work on all versions of windows by using the ‘windows folder’ inspector. This is also nice in case your OS is not on the C drive:

Q: if (exists folder (pathname of windows folder & “\Microsoft.NET\Framework”) whose (exists file “netfxsbs10.exe” of it)) then (version of file “netfxsbs10.exe” of folder (pathname of windows folder & “\Microsoft.NET\Framework”)) as string else “Not Installed”

A: 2.0.50727.42

T: 1.860 ms

I: singular string

And here is a version that doesn’t require a WHOSE IT clause:

Q: if (exists file (pathname of windows folder & “\Microsoft.NET\Framework\netfxsbs10.exe”)) then (version of file (pathname of windows folder & “\Microsoft.NET\Framework\netfxsbs10.exe”)) as string else “Not Installed”

A: 2.0.50727.42

T: 1.704 ms

I: singular string

These have about the same evaluation time. I noticed that in the relevance debugger sometimes the first was faster and sometimes the second was faster.

(imported comment written by ncfb)

Thank you. I knew there had to be a way to call that windows folder instead of having to seperate it out.

(imported comment written by ncfb)

Okay, I ran into another issue. 1.0 does not use that same file for some reason. I found another file that will give me the version number but now I cant get the If/then statement working right. What am I missing?

(if (exists file (pathname of windows folder & “\Microsoft.NET\Framework\netfxsbs10.exe”)) then (version of file (pathname of windows folder & “\Microsoft.NET\Framework\netfxsbs10.exe” as string) else “Not installed”) else if (exists file (pathname of windows folder & “\Microsoft.NET\Framework\Install.exe”))then (version of file (pathname of windows folder & “\Microsoft.NET\Framework\Install.exe” as string) else “Not Installed”))

(imported comment written by jessewk)

Your if statement has some malfromed syntax. Yours currently looks like this:

( if (…) then ( (…) else (…) ) else if (…) then ( (…) else (…) ) )

You need it to look like this:

( if (…) then (…) else ( if (…) then (…) else (…) )

So try this:

(if (exists file (pathname of windows folder & “\Microsoft.NET\Framework\netfxsbs10.exe”)) then (version of file (pathname of windows folder & “\Microsoft.NET\Framework\netfxsbs10.exe” as string)) else if (exists file (pathname of windows folder & “\Microsoft.NET\Framework\Install.exe”)) then (version of file (pathname of windows folder & “\Microsoft.NET\Framework\Install.exe” as string)) else “Not Installed”)

However, I’m not sure that the file you are referencing is a valid check that .NET is installed. It looks to me like that is just the path of the installer.

If you do a search through the Fixlets in your console, you will likely find a number of Fixlets that detect .NET of various version. You should be able to build off these to target exactly what you want.

(imported comment written by ncfb)

The only one that does detect if .NET is installed that I know of is the installed apps but the webreports is not working properly. Is basically what I need is a fixlet or a relevance clause to detect all versions of .NET framework and then I need to deploy .NET 1.1 out to whoever does have 1.1 or 2.0

(imported comment written by brolly3391)

ncfb,

If we abandon your original method for determining the install level of .NET and go with the MS suggested method found here: http://support.microsoft.com/kb/318785/en-us

then we find that we need to check for the file Mscorlib.dll in the subfolders of the folder found at this registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework

InstallRoot

Which, if we translate that into relevance and add all our existance checks along the way, we get something like this:

q: if (exists key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework” whose (exists value “InstallRoot” whose ( exists folder whose (exists file “Mscorlib.dll” of it) of folder (it as string) ) of it) of registry) then (versions of files “Mscorlib.dll” of folders of folder (value “InstallRoot” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework” of registry as string) as string) else (“Not Installed”)

A: 1.1.4322.2032

A: 2.0.50215.44

T: 5.136 ms

I: plural string

or if you prefer a concatenated answer that will work better in the console for machines where there is more than one framework installed:

q: if (exists key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework” whose (exists value “InstallRoot” whose ( exists folder whose (exists file “Mscorlib.dll” of it) of folder (it as string) )of it) of registry) then (concatenation " – " of (versions of files “Mscorlib.dll” of folders of folder (value “InstallRoot” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework” of registry as string) as string) ) else “Not Installed”

A: 1.1.4322.2032 – 2.0.50215.44

T: 5.636 ms

I: singular string

Originally I thought you wanted a retrieved property for the console, relevance for a fixlet is much easier :

q: not (exists key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework” whose (exists value “InstallRoot” whose ( exists folder whose (exists file “Mscorlib.dll” whose (version of it >“1.1.0.0”) of it) of folder (it as string) ) of it) of registry)

A: False

T: 3.804 ms

I: singular boolean

that should be true on any machine that has either no .NET or .NET less than 1.1. Any machine that has a .NET greater than 1.1.0.0 will not get the action.

Cheers,

Brolly

(imported comment written by khanand91)

Does anyone have an update to this that included .NET 3.0 - it’s seems that this method does not detect version 3.0 :frowning:

(imported comment written by Richard_Betts)

You can also use this to get the latest version installed.

if (exists key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework” whose (exists value “InstallRoot” whose ( exists folder whose (exists file “Mscorlib.dll” of it) of folder (it as string) ) of it) of registry) then (maximum of (versions of files “Mscorlib.dll” of folders of folder (value “InstallRoot” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework” of registry as string) as version)) as string else “Not Installed”

(imported comment written by jpeppers91)

The statement in the previous post gets an error? Any idea what’s wrong?

Error: The expression could not be evaluated for an unknown reason.

(imported comment written by BenKus)

Hey jpeppers,

What version of the agent and/or the relevance debugger are you using?

The expression that Richard posted uses "maximum of " inspector, which I think was added in BigFix 7.1.

You can check with this simple expression:

q: maximum of (“1.2.3.4” as version)

Ben

(imported comment written by khanand91)

Richards statement doesn’t detect version 3 or above, mainly due to the fact that mscorlib.dll doesn’t exists in the later versions …

I ended up using the statement below which is not the most attractive so was looking for something other than using folder paths.

if (exists folder “v3.5” of folder (value of variable “windir” of environment & “\Microsoft.NET\Framework” )) then “v3.5” else if (exists folder “v3.0” of folder (value of variable “windir” of environment & “\Microsoft.NET\Framework” )) then “v3.0” else if (exists key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework” whose (exists value “InstallRoot” whose (exists folder whose (exists file “Mscorlib.dll” of it) of folder (it as string)) of it) of registry) then (concatenation " - " of (versions of files “Mscorlib.dll” of folders of folder (value “InstallRoot” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework” of registry as string) as string)) else “Not Installed”