I am trying to determine which verison of .Net is installed (if it is installed) I have a bat file that does it and prompts the user to install it. I would like to redo this in MS to make it a little cleaner. I know I can read a registry key in MS, but what if the value is blank?
All I really need to do is query the registry to see if one of two lines are present. Can this be done quickly?
Here is the bat file
@ECHO OFF
CLS
REG QUERY HKLM\Software\Microsoft\.NETFramework\policy\v2.0
If errorlevel 1 (
GOTO check3
) ELSE (
GOTO RunProgram
)
:check3
REG QUERY HKLM\Software\Microsoft\.NETFramework\policy\v3.0
If errorlevel 1 (
GOTO InstallDotNet
) ELSE (
GOTO RunProgram
)
:RunProgram
START pdffg-gui.exe
EXIT
:InstallDotNet
CLS
ECHO Error: To run this software, you must have the required version of the .Net Framework installed on your computer (version 2.0).
ECHO You will be redirected to a webpage with instructions on installing it.
PAUSE
START iexplore.exe "http://www.microsoft.com/downloads/deta ... laylang=en"
EXIT
Determine if .Net is installed with MS
Moderators: JRL, Dorian (MJT support)
Rewrote your batch file to what I think is correct. I do not have .NET installed so I can't test the affirmative but this script tells me .NET is not installed and takes me to the website.
If>var=
tests positive.
Here's an attempt at your rewrite. The registry value may not be correct. Since I don't have it I don't know for certain how the values look. I took a guess at how the RegistryReadKey> line should be formatted.
If the registry entry does not exist (value is blank), The variable is set to nothing and therefore the line:I know I can read a registry key in MS, but what if the value is blank?
If>var=
tests positive.
Here's an attempt at your rewrite. The registry value may not be correct. Since I don't have it I don't know for certain how the values look. I took a guess at how the RegistryReadKey> line should be formatted.
Code: Select all
Let>RP_WAIT=1
RegistryReadKey>HKEY_LOCAL_MACHINE,Software\Microsoft\.NETFramework\policy,v2.0,var
If>%var%=
RegistryReadKey>HKEY_LOCAL_MACHINE,Software\Microsoft\.NETFramework\policy,v3.0,var
If>%var%=
MDL>Error: To run this software, you must have the required version of the .Net Framework installed on your computer (version 2.0). You will be redirected to a webpage with instructions on installing it.
Run>C:\Program Files\Internet Explorer\IEXPLORE.EXE http://www.microsoft.com/downloads/details.aspx?FamilyID=0856EACB-4362-4B0D-8EDD-AAB15C5E04F5&displaylang=en
EndIf
EndIf
Run>[Path]\pdffg-gui.exe
Determining Registry Value
I like the concept, (just what I was looking for) but I still have a little issue. What happens is there is a (default) value under policy, which is blank on my machine and one that says 50727. If I read the 50727 I have a value and it is installed. However, this could be a version number or something, therefore it would not work in all cases if the folder was different. I am pretty sure I just need to check if the folder v2.0 or v3.0 is present. Any ideas on how to do that? Oh yes, thank you for your help on this.
RegistryReadKey>HKEY_LOCAL_MACHINE,Software\Microsoft\.NETFramework\policy\v2.0,50727,var
Reads the value.
RegistryReadKey>HKEY_LOCAL_MACHINE,Software\Microsoft\.NETFramework\policy\v2.0,50727,var
Reads the value.
From info in this post. The following uses a DOS method (Which for some reason I'm particularly fond of) but there is also a VB script method mentioned for reading the registry contents. Be aware that the Separate> portion will be case sensitive so you may want to change the case on the text to all upper or all lower before using it to test for v2.0 or v3.0 or also test for V2.0 and V3.0
Code: Select all
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run>cmd /c regedit /E:A %TEMP_DIR%regread.txt HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\policy
ReadFile>%TEMP_DIR%regread.txt,contents_var
DeleteFile>%TEMP_DIR%regread.txt
Separate>%contents_var%,v2.0,test_var
If>%test_var_count%>1,NetInstalled,NetNotInstalled
Label>NetInstalled
Label>NetNotInstalled
Determine if .Net is installed solution
Thank you for your help, what I decided to do is use both the bat file and MS to determine if .Net is open.
I changed the bat file to copy/rename a file if .Net is present
.bat file ________________________________________________
@ECHO OFF
CLS
REG QUERY HKLM\Software\Microsoft\.NETFramework\policy\v2.0
If errorlevel 1 (
GOTO check3
) ELSE (
Copy C:\consolegrab\PDFCreation\version.2 C:\consolegrab\PDFCreation\version.txt
EXIT
)
:check3
REG QUERY HKLM\Software\Microsoft\.NETFramework\policy\v3.0
If errorlevel 1 (
GOTO InstallDotNet
) ELSE (
Copy C:\consolegrab\PDFCreation\version.3 C:\consolegrab\PDFCreation\version.txt
)
EXIT
___________________________________________________
Then I included a subroutine to see if the text file is there and if it is to read it and update the menu. It is updated with the version number as the file version.3 just contains Version 3.0 which has been copied to version.txt if it is present.
If it is not present it will return to a MS menu and ask the user if they want to download it.
This is the MS portion
SRT>testdotnet
IfFileExists>C:\consolegrab\PDFCreation\version.txt
Readln>C:\consolegrab\PDFCreation\version.txt,1,version
Let>CreatePDFOutputDialog.MSLABEL3=%version% of .Net is Installed
Goto>havedotnet
Endif
Let>RP_WAIT=1
Let>WINDOWMODE=0
Run Program>C:\consolegrab\PDFCreation\test.bat
IfFileExists>C:\consolegrab\PDFCreation\version.txt
Readln>C:\consolegrab\PDFCreation\version.txt,1,version
MDL>%version% of .Net is Installed
Let>CreatePDFOutputDialog.MSLABEL3=%version% of .Net is Installedstalled
Goto>havedotnet
Endif
Ask>Cannot find .Net - Download from Microsoft?,download
If>download=YES
MDL>You will be directed to Microsofts Website - run test again after .Net is installed
Executefile>http://www.microsoft.com/downloads/deta ... laylang=en
Else
MDL>The Fields cannot be imported without .Net
Endif
Label>havedotnet
ResetDialogAction>CreatePDFOutputDialog
End>testdotnet
I changed the bat file to copy/rename a file if .Net is present
.bat file ________________________________________________
@ECHO OFF
CLS
REG QUERY HKLM\Software\Microsoft\.NETFramework\policy\v2.0
If errorlevel 1 (
GOTO check3
) ELSE (
Copy C:\consolegrab\PDFCreation\version.2 C:\consolegrab\PDFCreation\version.txt
EXIT
)
:check3
REG QUERY HKLM\Software\Microsoft\.NETFramework\policy\v3.0
If errorlevel 1 (
GOTO InstallDotNet
) ELSE (
Copy C:\consolegrab\PDFCreation\version.3 C:\consolegrab\PDFCreation\version.txt
)
EXIT
___________________________________________________
Then I included a subroutine to see if the text file is there and if it is to read it and update the menu. It is updated with the version number as the file version.3 just contains Version 3.0 which has been copied to version.txt if it is present.
If it is not present it will return to a MS menu and ask the user if they want to download it.
This is the MS portion
SRT>testdotnet
IfFileExists>C:\consolegrab\PDFCreation\version.txt
Readln>C:\consolegrab\PDFCreation\version.txt,1,version
Let>CreatePDFOutputDialog.MSLABEL3=%version% of .Net is Installed
Goto>havedotnet
Endif
Let>RP_WAIT=1
Let>WINDOWMODE=0
Run Program>C:\consolegrab\PDFCreation\test.bat
IfFileExists>C:\consolegrab\PDFCreation\version.txt
Readln>C:\consolegrab\PDFCreation\version.txt,1,version
MDL>%version% of .Net is Installed
Let>CreatePDFOutputDialog.MSLABEL3=%version% of .Net is Installedstalled
Goto>havedotnet
Endif
Ask>Cannot find .Net - Download from Microsoft?,download
If>download=YES
MDL>You will be directed to Microsofts Website - run test again after .Net is installed
Executefile>http://www.microsoft.com/downloads/deta ... laylang=en
Else
MDL>The Fields cannot be imported without .Net
Endif
Label>havedotnet
ResetDialogAction>CreatePDFOutputDialog
End>testdotnet