SCCM 2012 – Deploy Visual Studio (Application Model)

If you want to deploy Micrsoft Visual Studio with System Center 2012 it will not working because the installer runs with the System Account. See this errors here:

http://social.technet.microsoft.com/Forums/en-US/2ad1e6b6-608d-44bb-bc58-2508becf4620/sccm-2012-osd-application-installation-using-local-administrator-account-instead-of-system-account?forum=configmanagerosd

http://social.msdn.microsoft.com/Forums/vstudio/en-US/60f57470-ac4e-4d40-8900-6599b4dca66f/visual-studio-2013-unattended-installation-fails-when-deployed-via-sccm-2012?forum=vssetup

I’ve got to install Visual Studio with some little tricks. You need following Applications (Script Installer):

  • Microsoft Visual Studio Prerequisite
  • Microsoft Visual Studio
  • The first script will create a local Account with Admin Rights and disable UAC. If you don’t disable UAC you need a user interaction. In most cases you don’t want this.

    The following script is a template that i use for my Applicaton Install with a Script Installer. It creates a Registry Entry (VisualStudio_Prerequisite_1.0.0) in HKLM:\Software\YourCompany for the Detection Method that will looks like this:

    vs1

    The script is called with following command (Install):

    powershell.exe -File "visualstudio_requirement.ps1" -InstallOption 1
    

    Uninstall:

    powershell.exe -File "visualstudio_requirement.ps1" -InstallOption 0
    

    vs2

    param([string]$InstallOption)
    
    ##################################################
    # Write Registry Entry for CM					 #
    # DON'T FORGET TO CHANGE PROGRAM NAME!!! 		 #
    # Values are 0 (Not installed) and 1 (Installed) #
    ##################################################
    
    $program = "VisualStudio_Prerequisite_1.0.0" # <-- Change this
    $installed = "1"
    $fhvPath = "HKLM:\Software\YourCompany"
    
    # Function for Installation
    Function Install()
    {
    # Write Key
    $properties = Get-ItemProperty -Path $fhvPath -ErrorAction SilentlyContinue
    if($properties -eq $null )
    {
    New-Item -Path HKLM:\Software\ -Name YourCompany
    }
    
    # Write Value
    $properties_program = Get-ItemProperty $fhvPath -Name $program -ErrorAction SilentlyContinue
    if($properties_program -eq $null )
    {
    New-ItemProperty -Path $fhvPath -Name $program -PropertyType String -Value $installed
    }
    
    ########################################
    # Installation Command
    
    # Create Local User
    net user localvisual localvisual /add /passwordchg:no | Out-Null
    net localgroup Administrators localvisual /add | Out-Null
    
    Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name ConsentPromptBehaviorAdmin -Value 1
    Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLUA -Value 0
    
    ########################################
    }
    
    # Function for Uninstallation
    Function Uninstall()
    {
    Remove-ItemProperty -Path $fhvPath -Name $program
    
    ###################################################################
    # Uninstall Command
    
    # Disabe User
    net user localvisual /delete | Out-Null
    
    # Enable UAC
    Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLUA -Value 1
    Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name ConsentPromptBehaviorAdmin -Value 5
    ###################################################################
    }
    
    # See what Argument was passed
    if ($InstallOption -eq "1")
    {
     Install
    }
    elseif ($InstallOption -eq "0")
    {
     Uninstall
    }
    else
    {
    Write-Host "Unknown Argument! Argument for InstallOption can be 0 (Install) and 1 (Uninstall)"
    }
    

    The Application Microsoft Visual Studio Prerequisite is only a dependency for the afterwards created Microsoft Visual Studio Application. You don’t must cretae any Deployments. After the installation of the Prerequise you must Reboot your computer. So you need to change this:

    vs3

    Now we can create the main Application (Microsoft Visual Studio). Create an Application (Script Installer) with the same templates as above. For example here is my script. As you can see the Detection Method is here also a Registry entry with VisualStudio_2013.3.0 as Key.

    param([string]$InstallOption)
    
    ##################################################
    # Write Registry Entry for CM					 #
    # DON'T FORGET TO CHANGE PROGRAM NAME!!! 		 #
    # Values are 0 (Not installed) and 1 (Installed) #
    ##################################################
    
    $program = "VisualStudio_2013.3.0" # <-- Change this
    $installed = "1"
    $fhvPath = "HKLM:\Software\YourCompany"
    
    # Function for Installation
    Function Install()
    {
    # Write Key
    $properties = Get-ItemProperty -Path $fhvPath -ErrorAction SilentlyContinue
    if($properties -eq $null )
    {
    New-Item -Path HKLM:\Software\ -Name YourCompany
    }
    
    # Write Value
    $properties_program = Get-ItemProperty $fhvPath -Name $program -ErrorAction SilentlyContinue
    if($properties_program -eq $null )
    {
    New-ItemProperty -Path $fhvPath -Name $program -PropertyType String -Value $installed
    }
    
    ########################################
    # Installation Command
    
    # Install VS2013
    $computer = $env:computername
    .\PsExec.exe -accepteula -u $computer\localvisual -p localvisual -h $PSScriptRoot\vs_ultimate.exe /noweb /full /quiet /norestart /ProductKey xxxxxxxxxxxxxxxxxx| Out-Null
    
    # Disabe User
    net user localvisual /delete | Out-Null
    
    # Enable UAC
    Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLUA -Value 1
    Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name ConsentPromptBehaviorAdmin -Value 5
    ########################################
    }
    
    # Function for Uninstallation
    Function Uninstall()
    {
    Remove-ItemProperty -Path $fhvPath -Name $program
    
    ###################################################################
    # Uninstall Command
    
    # Uninstall Visual Studio
    .\vs_ultimate.exe /Uninstall /Silent /Quiet | Out-Null
    ###################################################################
    }
    
    # See what Argument was passed
    if ($InstallOption -eq "1")
    {
     Install
    }
    elseif ($InstallOption -eq "0")
    {
     Uninstall
    }
    else
    {
    Write-Host "Unknown Argument! Argument for InstallOption can be 0 (Install) and 1 (Uninstall)"
    }
    

    Please note: The installation files of Visual Studio 2013, PSExec and the script are in the same root folder. You must download PSExec from this site:

    The important line is this:

    .\PsExec.exe -accepteula -u $computer\localvisual -p localvisual -h $PSScriptRoot\vs_ultimate.exe /noweb /full /quiet /norestart /ProductKey xxxxxxxxxxxxxxxxxx| Out-Null
    

    We start now the installer with the previously created user localvisual. To run the Installer successfully we must provide the absolute path, so we need the variable $PSScriptRoot. After the installation we delete the previously created user localvisual and enable UAC.

    The Application Microsoft Visual Studio Prerequisite is a prerequisite of the Microsoft Visual Studio Application, as you can see in the screenshots.

    vs6

    vs5

    vs4

    Hopefully this helps somebody.