• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Help with .bat file creation

MjrStryker

Gawd
Joined
Dec 9, 2005
Messages
981
I'm trying to find out how to use a .bat file to check the version of the dot net framework currently installed on a user's computer.

I want to be able to distribute my programs on CD without requiring that they be installed to the hard drive, however I'm using Visual Studio.NET 2005 to write my programs, so I need to check that at least version 2.0 of the dot net framework is installed when the CD is inserted. If it's not installed, I want the batch file to execute the framework redistributable to install it so that my program can run.

From my research I've found that the dot net framework adds the following registry key for version 2.0:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\Policy\v2.0

However, the only value in this subkey is variable depending on the build. All I want to check for is whether that particular subkey exists or not and then run another action accordingly.

I've tried using REG QUERY but I can't seem to get the syntax right. It's my first time attempting to write a complex batch file such as this.
 
maybe something like this?
Code:
if not exist "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\Policy\v 2.0" (GOTO INSTALL) else (GOTO END)

:INSTALL

"\\server\share\whatever.exe"

:END

May need a little tweaking but it seems pretty straight forward. Also need to get the .net framework installer to run silent.
 
That helps quite a bit. I've now gotten it to where it can detect the subkey I needed and correctly chooses whether to run the dotnetfx.exe or the setup.exe for my program.

Now any idea on how to make it wait until the dotnetfx.exe is finished before moving on to the setup.exe?
 
Will IF NOT EXIST test for a registry key? I thought it would only test for a file name (or directory name).
 
No, it doesn't appear it will test for a registry key. I should've made my reply a bit more clear. The syntax of jonw757 was more of what helped than the exact line of code. I had no idea that "If" statements could be run in batch files and since then have modified my code a bit. Here is what I've got so far:

Code:
@ECHO off
cls
set DOTNETINSTALLED=NO

REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\Policy\v2.0" >NUL && set DOTNETINSTALLED=YES

IF %DOTNETINSTALLED%==YES goto MAIN
goto PREREQUISITE

:MAIN
REM Execute Main Setup Program
START "D:\MGM Paradigm Setup" D:\"MGM Paradigm Setup.exe"
goto ENDOFFILE

:PREREQUISITE
REM Execute Prerequisite Setup Program
START "D:\dotnetfx.exe" D:\dotnetfx.exe
goto ENDOFFILE

:ENDOFFILE

I would like the :pREREQUISITE option to simply run the dotnetfx.exe before running the MGM Paradigm Setup.exe however I don't know how to set my program to wait for dotnetfx.exe to finish.
 
Wouldn't a "pause" do the waiting for you. I don't know exactly how you would want to incorporate that with your batch, but that would do the waiting part.
 
"pause" seems to wait for the user to input information though, it doesn't do anything about a currently executing program.
 
You might also want to make the path statements open as not everyones CD drives are drive "D". I cannot remember the syntax for it though. I'd have to dig through some of my older batch file creations. I've made some pretty massive and advanced ones in the past.
 
Yeah I think just make it relative from the batch file location
.\folder\exefile.exe
or ..\folder\exefile.exe
etc.
 
Thanks so much. The /wait parameter seems to work just fine. :D I appreciate all the help. Now I'm off to search the forums for how to do something similar in vb.net for the rest of my program. Lol
 
In case anyone wants this code later, I'll post the finished version. Replace [App To Run] with the relative location of your application from the bat file and [Dot Net Installer] with the relative location of your dotNetFramework 2.0 installer. The code will check to see if DotNET 2.0 is installed and if not, attempt to install it before running the app.

Code:
@ECHO off
cls
set DOTNETINSTALLED=NO

REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\Policy\v2.0" >NUL && set DOTNETINSTALLED=YES

IF %DOTNETINSTALLED%==YES goto MAIN
goto PREREQUISITE

:PREREQUISITE
REM Execute Prerequisite Setup Program
START /wait "[Dot NET Installer]" [Dot NET Installer]

:MAIN
REM Execute Main Setup Program
START /wait "[App To Run]" [App To Run]
 
Back
Top