Automated installation of SQL Server 2012 for TFS “11″ at the command line

Posted by Stuart Preston on April 6, 2012 under ALM, Application Lifecycle Management, Team Foundation Server, Visual Studio | Read the First Comment

If I had one pound sterling for every Team Foundation Server install I’ve performed in my life I’d be a rich man by now. Back in late 2004/early 2005 when a number of us were playing with the alpha TFS 2005 bits, all the components had to be installed on a separate machines and if you made the slightest mistake it was a rebuild job from the bare metal – of course Virtualisation technologies like snapshotting weren’t mainstream in those days and installation was a pain!

Fast forward 8 years and here we are; .NET Framework is properly integrated as a system component in the OS, Virtualisation and snapshotting is the norm, disks have got much faster, TFS installs in minutes (not hours) and automatically configures IIS and all the prerequisites it needs, which makes life amazingly easy.

Grant Holliday wrote this article that I still refer to when I need to build a TFS2010 virtual machine from scratch so when I came to installing a brand new Windows 8 Server with SQL Server 2012 and TFS “11″ in a Virtual Machine I had to do a little bit of thinking for myself.

Assuming you want to create a Default instance of SQL Server 2012 complete with Analysis Services and SQL Server Reporting Services (SSRS) as if you had accepted all the defaults:

  • start with a completely blank Windows 8 Server image with no roles or features added
  • mount the disk in your favourite manner (i.e. mount the .iso image on your host machine from the menu on your guest VM, or use Virtual CloneDrive to mount the .iso file locally)
  • at a new administrator command prompt, replace the highlighted bits with a valid user who you wish to have full access to everything!) and paste the whole thing:
d:\setup.exe /QS /ACTION="Install" /ENU /UpdateEnabled /FEATURES=SQLENGINE,FULLTEXT,AS,RS,SSMS,ADV_SSMS /UpdateSource="MU" /INDICATEPROGRESS="True" /X86="False" /INSTALLSHAREDDIR="C:\Program Files\Microsoft SQL Server" /INSTALLSHAREDWOWDIR="C:\Program Files (x86)\Microsoft SQL Server" /INSTANCENAME="MSSQLSERVER" /INSTANCEID="MSSQLSERVER" /SQMREPORTING="False" /RSINSTALLMODE="DefaultNativeMode" /ERRORREPORTING="False" /INSTANCEDIR="C:\Program Files\Microsoft SQL Server" /AGTSVCACCOUNT="NT Service\SQLSERVERAGENT" /AGTSVCSTARTUPTYPE="Manual" /ASSVCACCOUNT="NT Service\MSSQLServerOLAPService" /ASSVCSTARTUPTYPE="Automatic" /ASCOLLATION="Latin1_General_CI_AS" /ASDATADIR="C:\Program Files\Microsoft SQL Server\MSAS11.MSSQLSERVER\OLAP\Data" /ASLOGDIR="C:\Program Files\Microsoft SQL Server\MSAS11.MSSQLSERVER\OLAP\Log" /ASBACKUPDIR="C:\Program Files\Microsoft SQL Server\MSAS11.MSSQLSERVER\OLAP\Backup" /ASTEMPDIR="C:\Program Files\Microsoft SQL Server\MSAS11.MSSQLSERVER\OLAP\Temp" /ASCONFIGDIR="C:\Program Files\Microsoft SQL Server\MSAS11.MSSQLSERVER\OLAP\Config" /ASPROVIDERMSOLAP="1" /ASSYSADMINACCOUNTS="VS11BETA\Administrator" /ASSERVERMODE="MULTIDIMENSIONAL" /SQLSVCSTARTUPTYPE="Automatic" /FILESTREAMLEVEL="0" /SQLCOLLATION="Latin1_General_CI_AS" /SQLSVCACCOUNT="NT Service\MSSQLSERVER" /SQLSYSADMINACCOUNTS="VS11BETA\Administrator" /TCPENABLED="1" /NPENABLED="0" /BROWSERSVCSTARTUPTYPE="Disabled" /RSSVCACCOUNT="NT Service\ReportServer" /RSSVCSTARTUPTYPE="Automatic" /FTSVCACCOUNT="NT Service\MSSQLFDLauncher" /IAcceptSQLServerLicenseTerms

Installation will progress for a while but when finished you have all the components required to do the TFS 11 install immediately afterwards.

Running and debugging a .NET application as Network Service in Visual Studio 2010

Posted by Stuart Preston on May 18, 2010 under Development Practices, Visual Studio | Be the First to Comment

This post generated some interest on a discussion list so I’m re-posting here on my blog.  Cutting a longer story short, the original poster wanted a way to start a process as Network Service rather than as the current Windows identity to mitigate the risk that you have more rights than you should have. 

For those who have tried to use “runas” to achieve this you are left with the rather bleak message: “RUNAS ERROR: Unable to acquire user password”. 

image

I’ll skip the reasons for this and go straight onto the solution.  Create a dummy service using the Service Manager (sc.exe).  This launches the application in the right session and is allowed to run as Network Service or even Local System (NT Authority\Local System).

@echo off
sc delete NetworkServiceCmd >nul:
sc create NetworkServiceCmd binpath= “cmd /K start c:\neverendingapp.exe” obj= “NT Authority\Network Service” >nul:
sc start NetworkServiceCmd >nul:
sc delete NetworkServiceCmd >nul:

Simply drop the above into a batch file and run it.  You can then use “Attach to Process” in Visual Studio to attach to the process (don’t forget that your PDB’s must be in the same location as the assembly).

image

Here’s a screenshot of the debugger attached to my “NeverEndingApp” and viewing the current identity.

image

You need to manually kill off the process you started, you can use Task Manager as usual or here’s a macro I use that works in my scenario.  You can attach this to a Keyboard Shortcut or even a Toolbar.

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module TerminateProcess

    Public Function TerminateProcess()

        Dim processes As EnvDTE.Processes = DTE.Debugger.LocalProcesses
        Dim process As EnvDTE.Process

        For Each process In processes
            If (process.Name.ToLower().Contains(“neverendingapp.exe”)) Then
                process.Terminate(True)
            End If
        Next

End Function
End Module

I’m certain all the above can be improved on but I think all the basics are in here and customising it for your process is a challenge I’ll leave to the reader!