Monday, September 22, 2014

Enable .Net Framework 3.5 SP1 in Windows 8.1

I thought I would right up how I enable .Net Framework 3.5 SP1 in Windows 8.1 using SCCM and PowerShell. Both as an application that can be pushed to machines, and during OS deployments in the task sequence.
First create a powershell script with the command:
# Enable .Net 3.5 Framework SP1 on Windows 8.1 Machines.
# Must have SXS folder from Windows 8.1 ISO in directory with script
#Enable .Net 3.5
enable-windowsoptionalfeature -featurename NetFx3 -Online -NoRestart -LimitAccess -All -Source .\SXS -LogLevel WarningsInfo -ErrorAction Continue
I call my script “EnableNet35.ps1”.
Next you will need the folder “sxs” from your Windows 8.1 ISO disk. This folder is located in the sources folder. My ISO is on a network share so the path may be different from yours.

Copy this folder and your script to your SCCM Source folder.

Create your Application and Deployment Type like so:



We will use a Custom PowerShell script as the detection method.

If ((Get-windowsoptionalfeature -FeatureName NetFx3 -Online | Select-Object -ExpandProperty State) -ne "Enabled")
        {
        # .NET Framework 3.5SP1 is not enabled on this system
        Exit
        }
    Else
        {
            # Its installed so populate 'stdout', write-host will do this
            Write-host ".NET Framework 3.5 SP1 is already installed"
            Exit
        }


If you wish to use this in an OSD Task Sequence, or any PowerShell commands, you may have to enable PowerShell during the Task Sequence.

How to Enable PowerShell during an OSD Task Sequence.

You will have to input settings into the registry of the computer to allow it to run PowerShell unrestricted. I use the following script (thanks Nash Pherson and JDA for the script):
@ECHO OFF
CLS
REM http://social.technet.microsoft.com/Forums/en-US/501bc91f-4dae-4917-a2b2-0a3c3a7fce86/set-powershell-execution-policy-as-part-of-a-task-sequence?forum=mdt
REM JDA 2/25/14

:breakout
IF EXIST %SystemRoot%\Sysnative\cmd.exe ("%SystemRoot%\Sysnative\cmd.exe" /C "%~dpnx0") & (GOTO end)

:policy
reg add HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell /t REG_DWORD /v EnableScripts /d 1 /f
reg add HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell /v ExecutionPolicy /d Unrestricted /f
reg add HKLM\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell /t REG_DWORD /v EnableScripts /d 1 /f
reg add HKLM\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell /v ExecutionPolicy /d Unrestricted /f

:end
Name this script “enable_ps.cmd” and create a SCCM package called Enable PowerShell with “enable_ps.cmd” as the Command Line.

Run this package early in your OSD Task Sequence before your first PowerShell script executes.

Thursday, September 18, 2014

Silently Deploy FMAPlus 3 via SCCM

* Script updated 8/19 to fix an issue.

FMAPlus 3 or Fuels Management Analyst is a software we use in our Forestry computing labs here at the university. While tackling the install and user setup, I decided to try working with PowerShell since I was learning it. If you don't use PowerShell, you can modify the commands for your scripting language of choice.

We are going to script the following:
1) Install FMAPlus for all users silently.
2) Copy a folder full of photos to the FMAPlus 3 directory in Program Files.
3) Use active setup to register the software and point to the photo folder.
4) Copy a settings file to Program Files.
5) Change the permissions on the FMAPlus 3 directory in Program Files to allow Users to Modify.
6) Remove the shortcut from the desktop.
7) Rename the shortcut in the Start Menu from "Gateway.lnk" to "FMAPlus 3.lnk"

I will take you through each step, explain what I did and then combine everything at the end into the PowerShell script and SCCM application deployment. These techniques may be useful when you are trying to create your own installer scripts.

1) Install FMAPlus for all users silently.

$currentDirectory = split-path -parent $MyInvocation.MyCommand.Definition
Start-Process $currentDirectory\fma300.exe -ArgumentList '/S /v"/qn ALLUSERS=2"' -Wait

The /v parameter passes parameters to the MSI that gets extracted during the install to C:\Windows\Installer. I wanted to pass the /qn (silent) and the ALLUSERS=2 property, otherwise the shortcuts in the Start Menu would only exist for the user that ran the install, in my case, the SYSTEM account. Which means there would be no shortcuts in the Start Menu for the lab users. The fact that the .EXE extracts the MSI to the C:\Windows\Installer folder and leaves it there after completing setup is nice, I was able to find it after running a hardware inventory on a test computer after installing the software by hand. This helped me get the GUID from the MSI for the detection method later.

2) Copy a folder full of photos to the FMAPlus 3 directory in Program Files.

Copy-Item -Path PhotoImages -Destination 'C:\Program Files (x86)\FMAPlus 3\PhotoImages' -Recurse -Force


Self Explanatory. Copy-Item does exactly what it says! I am not sure but I think this folder contains special photo's our faculty use in classes. Regardless, the lab team tells me it needs to be there so I put it there.

3) Use active setup to register the software and point to the photo folder.

We need to use active setup for this install as the program registers its license per user in the HKCU  
registry. So what I did was install the application on a VM, put in the license code during the first run, run Photo Manager and set the Photo Image Location. Export the keys located at: 
HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Fuels Management Analyst 3\General] .  Here I have the reg file I exported, substitute the "X"s with your own license code. The reg file should look like: 

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Fuels Management Analyst 3\General]
"RegNumber1"="xxxx"
"RegNumber2"="xxxxx"
"RegNumber3"="xxxx"
"RegNumber4"="xxxxx"
"Registered"="True"
"CMIExample"="True"
"PhotoDir"="c:\\Program Files (x86)\\FMAPlus 3\\


I cant remember what "CMIExample" is for, but it may not need to be set to remove first run prompts. Save this reg file to your source directory with the install file. I call mine "hkcu_fmaplus.reg" 
The following PowerShell command copies the reg file to the Program Files: 


Copy-Item -Path hkcu_fmaplus3.reg -Destination 'C:\Program Files (x86)\FMAPlus 3\hkcu_fmaplus3.reg'
And these three commands setup the active setup:

New-Item -Path Registry::'HKLM\Software\Microsoft\Active Setup\Installed Components\HSU-FMAPlus3' -Force
New-ItemProperty -Path Registry::'HKLM\Software\Microsoft\Active Setup\Installed Components\HSU-FMAPlus3' -Name StubPath -PropertyType String -Value 'CMD /C REG IMPORT "%ProgramFiles(x86)%\FMAPlus 3\hkcu_fmaplus3.reg"' -Force
New-ItemProperty -Path Registry::'HKLM\Software\Microsoft\Active Setup\Installed Components\HSU-FMAPlus3' -Name Version -PropertyType String -Value '2,0,0,0' -Force

4) Copy a settings file to Program Files.

When you run Fuel Model Manager the first time, it prompts you if you have existing custom fuel models from version 2 and do you want to load them, it then creates a file called "MyFuelModels.FFM" in the program directory. We don't have any custom models from our labs, so I click no and save the "MyFuelModels.FFM" file to my source directory. During installation, I copy this file back into the Program Directory with this command: 


Copy-Item -Path MyFuelModels.FFM -Destination 'C:\Program Files (x86)\FMAPlus 3\MyFuelModels.FFM'

5) Change the permissions on the FMAPlus 3 directory in Program Files to allow Users to Modify.

When the program is run by the user, it creates shortcuts in the Program Files\FMAPlus 3 folder for some ungodly reason, and if it can't, the program errors out. Users typically don't have permissions to write to Program Files, so we must modify the folder to allow them to write.

$Acl = Get-Acl 'C:\Program Files (x86)\FMAPlus 3'
$Arguments = "BUILTIN\Users","FullControl","ContainerInherit, ObjectInherit", "None", "Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $arguments
$Acl.SetAccessRule($accessRule)
$acl | Set-Acl 'C:\Program Files (x86)\FMAPlus 3'

6) Remove the shortcut from the desktop.

if (Test-Path 'C:\Users\Public\Desktop\FMAPlus 3.lnk')
{
  Remove-Item -Path 'C:\Users\Public\Desktop\FMAPlus 3.lnk' -Force
}

7) Rename the shortcut in the Start Menu from "Gateway.lnk" to "FMAPlus 3.lnk"

Rename-Item 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\FMAPlus 3\Gateway.lnk' 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\FMAPlus 3\FMAPlus 3.lnk'

Putting It All Together

Combine all your PowerShell commands into a script, I called mine "install_fma.ps1"

$currentDirectory = split-path -parent $MyInvocation.MyCommand.Definition
# Install FMAPlus 3
Start-Process $currentDirectory\fma300.exe -ArgumentList '/S /v"/qn ALLUSERS=2"' -Wait

# Copy PhotoImages Repository
Copy-Item -Path PhotoImages -Destination 'C:\Program Files (x86)\FMAPlus 3\PhotoImages' -Recurse -Force

# Copy Active Setup Reg File
Copy-Item -Path hkcu_fmaplus3.reg -Destination 'C:\Program Files (x86)\FMAPlus 3\hkcu_fmaplus3.reg'

# Active Setup Registry Settings for License and First Run
New-Item -Path Registry::'HKLM\Software\Microsoft\Active Setup\Installed Components\HSU-FMAPlus3' -Force
New-ItemProperty -Path Registry::'HKLM\Software\Microsoft\Active Setup\Installed Components\HSU-FMAPlus3' -Name StubPath -PropertyType String -Value 'CMD /C REG IMPORT "%ProgramFiles(x86)%\FMAPlus 3\hkcu_fmaplus3.reg"' -Force
New-ItemProperty -Path Registry::'HKLM\Software\Microsoft\Active Setup\Installed Components\HSU-FMAPlus3' -Name Version -PropertyType String -Value '2,0,0,0' -Force

# Copy Fuel Model File
Copy-Item -Path MyFuelModels.FFM -Destination 'C:\Program Files (x86)\FMAPlus 3\MyFuelModels.FFM'

# Modify "C:\Program Files (x86)\FMAPlus 3" permissions
$Acl = Get-Acl 'C:\Program Files (x86)\FMAPlus 3'
$Arguments = "BUILTIN\Users","FullControl","ContainerInherit, ObjectInherit", "None", "Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $arguments
$Acl.SetAccessRule($accessRule)
$acl | Set-Acl 'C:\Program Files (x86)\FMAPlus 3'

# Remove Desktop Shortcut
if (Test-Path 'C:\Users\Public\Desktop\FMAPlus 3.lnk')
{
  Remove-Item -Path 'C:\Users\Public\Desktop\FMAPlus 3.lnk' -Force
}

# Rename Shortcut
Rename-Item 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\FMAPlus 3\Gateway.lnk' 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\FMAPlus 3\FMAPlus 3.lnk'

Gather up the fma300.exe installer, the hkcu_fmaplus3.reg registry file, your install script install_fma.ps1, the MyFuelModels.FFM file, and the PhotoImages folder and put them in your SCCM source location.




Create your Application and Deployment Type, the installation command is: 
powershell.exe -ExecutionPolicy Unrestricted -File install_fma.ps1



The GUID of the msi that extracted to C:\Windows\Installer when the EXE was ran is: 
{44D618AE-62C3-4564-B2EF-E00E226DE515}, so i use that for my detection method and uninstall program. YMMV if you have a different version so be sure to install it on a test computer first and see if it puts an msi in C:\Windows\Installer to get the GUID from.


Distribute and Deploy to your computers! 

Monday, September 8, 2014

Silently Deploy CyberLink PowerDVD with SCCM


Edit: Soon after finishing this post we updated to version 14 and I also changed the Active Setup to open PowerDVD when a blu ray disc is put in the blu ray player so i adjusted the script a bit to reflect the changes.

We purchased CyberLink PowerDVD software in order to play Blu-ray’s on our classroom computers that are connected to projectors. This is how I silently deploy it while handling the first run prompts. We will remove the Welcome Screen and turn off the prompt to join the Product Improvement program. Luckily, when you purchase the software from Cyberlink, the MSI has an in-built key so you don’t not have to handle registration.
First create a file called “db.ini” that contains
[Setup]
init=1
Next create a reg file that contains
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\CyberLink\PowerDVD13]
"UIEnableCEIP"=dword:00000000

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\EventHandlersDefaultSelection]
@=""

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\EventHandlersDefaultSelection\PlayBluRayOnArrival]
@="PowerDVD14.0PlayBluRayOnArrival"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\EventHandlersDefaultSelection\PlayDVDMovieOnArrival]
@="PowerDVD14.0PlayDVDMovieOnArrival"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\EventHandlersDefaultSelection\PlayEnhancedDVDOnArrival]
@="PowerDVD14.0PlayDVDMovieOnArrival"
I called my reg file “HKCU_POWERDVD.reg”

Then create your “install.cmd” file which contains
REM Installs PowerDVD and removes first run prompts.
:@ECHO OFF
:Location
Set loc=%~dp0
:Install
msiexec /i "%loc%PowerDVD14_3917_CorpBD_DVD140303-05.msi" /qn
:Configure
XCOPY "%loc%db.ini" "%SystemDrive%\Users\Default\AppData\Local\CyberLink\PowerDVD14\DB1038\" /Y
XCOPY "%loc%HKCU_POWERDVD.reg" "%ProgramFiles(x86)%\CyberLink\PowerDVD14\" /Y
REG ADD "HKLM\Software\Microsoft\Active Setup\Installed Components\HSU-PowerDVD" /v "StubPath" /t REG_SZ /d "CMD /C REG IMPORT \"%%ProgramFiles(x86)%%\CyberLink\PowerDVD14\HKCU_POWERDVD.reg\"" /f
REG ADD "HKLM\Software\Microsoft\Active Setup\Installed Components\HSU-PowerDVD" /v "Version" /t REG_SZ /d "2,0,0,0" /f
:CLEANUP
if exist "%PUBLIC%\Desktop\CyberLink PowerDVD 14.lnk" del "%PUBLIC%\Desktop\CyberLink PowerDVD 14.lnk"
GOTO END
:END
Put the 3 files you created along with the MSI in your SCCM Source location
(I know these photos are from our version 13 install, but you get the idea)


Create your Application and Deployment Type like so






The installer is an MSI so the detection method is easy, I love it.



Distribute the content to your Distribution Points and deploy!