Tuesday, November 23, 2010

How to Deploy Microsoft .NET Framework 4 with Group Policy with Startup Script

To deploy .NET Framework 4 to your network you must use a startup script. No longer can you push .NET Framework out via an MSI file as with earlier versions such as .NET Framework 1.1.

I wrote a script that your welcome to copy it to push the .NET framework to all x86 and x64 windows based PC's on your network.

Save the following as a ".bat" file.

setlocal

REM *********************************************************************
REM Environment customization begins here. Modify variables below.
REM *********************************************************************

REM Enter the Product Name.
set ProductName=Microsoft .NET Framework 4 Client Profile

REM Set DeployServer to a network-accessible location containing the Office source files.
set DeployServer=\\kbomb.local\netlogon\software

REM Set LogLocation to a central directory to collect log files.
set LogLocation=C:\Windows\Logs

REM *********************************************************************
REM Deployment code begins here. Do not modify anything below this line.
REM *********************************************************************

IF NOT "%ProgramFiles(x86)%"=="" (goto ARP64) else (goto ARP86)

REM Operating system is X64. Check for 32 bit Office in emulated Wow6432 uninstall key
:ARP64
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432NODE\Microsoft\Windows\CurrentVersion\Uninstall\%ProductName%"
if NOT %errorlevel%==1 (goto End)

REM Check for 32 and 64 bit versions of Office 2010 in regular uninstall key.(Office 64bit would also appear here on a 64bit OS)
:ARP86
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%ProductName%"
if %errorlevel%==1 (goto DeployOffice) else (goto End)

REM If 1 returned, the product was not found. Run setup here.
:DeployOffice
start /wait %DeployServer%\dotNetFx40_Full_x86_x64.exe /passive
echo %date% %time% Setup ended with error code %errorlevel%. >> %LogLocation%\%computername%.txt

REM If 0 or other was returned, the product was found or another error occurred. Do nothing.
:End

Endlocal


Please modify the DeployServer path to fit your environment.

Copy the script into the startup script folder inside the group policy object. Make sure you use a startup script and not a logon script! Refer to the following screenshot:



My script is called frameworkinstall.bat

Link this group policy object to your computer accounts. When the workstations refresh there group policy they will automatically install .NET Framework v4 on next reboot.

Taken with my iPhone 4:



Note: If you do not want the user to see the progress of the installation, please change /passive to /q. This will result in the PC hanging at the "Running Startup Scripts" for a few minutes. I personally prefer to present the users with a progress bar!

17 comments:

  1. How did you get around having to clik the 'I accept' thing on the first page?

    ReplyDelete
  2. I never got the i accept. Try making it a quite instAll

    ReplyDelete
  3. I get: setup error 5 on my log file

    ReplyDelete
    Replies
    1. how did you fix the error 5 issue?

      Delete
  4. thank you for sharing, really helpful - time saving!

    On some computers (5/50) however it installed just the client (not the extended version), didn't figure out why (logs).

    ReplyDelete
  5. Change...

    start /wait %DeployServer%\dotNetFx40_Full_x86_x64.exe /passive

    To...

    start /wait %DeployServer%\dotNetFx40_Full_x86_x64.exe /q /norestart

    --mcocker

    ReplyDelete
  6. Hi Clint, thank you for creating this page, it has been most helpful.
    I do, however have a query/problem..
    The above installations install the dotnet4 Client Profile onto the machines.
    I also need the 'extended' installation on there too.
    Now, when I run the original .exe manually on the local machine AFTER the above bat script has run, it does indeed install the extended version that I need next to the client profile..
    Is there any way via batch script to install the 'extended', as above?
    Kind Regards
    Nick

    ReplyDelete
  7. Nick, works fine for me and installs both client profile and extended.

    On a separate issue, make sure that the share containing the dotNet exe is readable by "domain computers" group.

    ReplyDelete
  8. Thank you very much for this blog!

    ReplyDelete
  9. In my case the error is displayed in the log. Setup ended with error code 5

    ReplyDelete
  10. Hi
    Fantastic script, thanks very much!
    I am having an issue where some machines have the .Net 4 Client profile installed already so the script does not run, and i need the extended part to .Net 4 installed. Any ideas on how to get around this, so the script runs?

    Thanks

    ReplyDelete
  11. Fixed.
    I replaced the productname with Extended instead of CLient Profile, making sure they both install when the script is run.
    Thanks!

    ReplyDelete
  12. How do you get around user access control? I would hate to have to disable that, seems like a bad idea.

    ReplyDelete
  13. Randescy, its a start up script, UAC should not take into effect.

    ReplyDelete
  14. Ok thank you. I was trying to test it while the os had fully loaded because it didn't run on startup. May have been the gp policy not applying to the pc though. I'll continue to play with it. I'm going to add the run script as a local policy. When trying to do this through gp does the script need to be locally stored?

    ReplyDelete
  15. The script can be stored on a file server, within the group policy object itself or locally on the machine as long as the workstation account has access to it. If you run it of a betwork share make sure authenticate users or domain computers has read rights to be able to launch the script.

    ReplyDelete
  16. We were push installing .NET 2.0 Framework onto remote machine using WMI and the msi used to install the .NET Framework. Now our applications are upgraded and target .NET 4.0 Framework. So when we push install then the installation of Framework doesn't seem to progress and doesn't complete. We have checked the Installation log and it looks like the installer is unable to update a config file as it doesn't contain the logging "[CheckFX ]: Writing config file with version: '4.0.0'...[CheckFX ]: Creating Config File..." when compared with the local installation. Also an error "[VsdLaunchConditions ]: Custom Action failed with code: '1603'" is logged. Please let us know whether it is possible to push install .NET Framework 4.0 using WMI.

    ReplyDelete