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.

    3 thoughts on “SCCM 2012 – Deploy Visual Studio (Application Model)

    1. Hello Benedickt!

      I have a MSI file called ClientSetupMSI.msi that I’m running into a lot of problems installing. It installs fine through SCCM, but for the program to run successfully first I have to run it as Administrator after it is installed or it won’t work.

      My thought is that the msi isn’t installing properly using the local system account. How could I incorporate your script above to just run the msi installer with a domain account? Any help would be greatly appreciated. I think your script here is very close to what I need to make this work.

      Thanks for your time!
      Tyson

      1. Forgot to mention I think UAC might be an issue also, so will probably need to disable UAC temporally.

      2. Hello!

        I think you can do this also with PSexec. You must create a application and then say “Manually specify the application information”. In the next steps you can add a Program. And here you must select “Script Installer” from the Type Drop Down. Then you can select your Skript or command line. I think your Installation command should look something like that:

        .\PsExec.exe -accepteula -u your_domain\domainuser-p password -h msiexec /i "ClientSetupMSI.mis /qb

        Don’t forget to disable UAC first. I think if it’s enabled it will not work. But i doesn’t know for sure. Maybe this will help you.

    Leave a Reply

    Your email address will not be published. Required fields are marked *