Using XP_cmdshell to install sql server

  • I have created a sproc that calls xp_cmdshell to install sql server. The full script(only posting the install part here) then does some other stuff like create data and log folders and updates the reg to point to these etc. The xp_cmdshell seems to time out on the install for lack of a better idea. But i don't really think thats it, as if i send a bad install command it never times out. So i was thinking permissions, so i changed the instance to run under my windows account with full admin (ya i know its not safe but this is dev machine 🙂 ) That didnt fix it.

    The sproc outputs the command args and if i copy and paste them into a cmd window sql server gets installed just fine.

    Long story short i am trying to create a single script to install and configure in detail all newly installed instances. I have everything else working in the full script excluding the install part.

    Anyone with some ideas let me know. You will have do adjust the script to point to correct drives and binaries for your environment. script below:

    USE [Admin]

    GO

    /****** Object: StoredProcedure [dbo].[p_NewInstance] Script Date: 04/24/2009 14:45:33 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    -- =============================================

    -- Author:

    -- Create date:

    -- Description:

    -- =============================================

    create PROCEDURE [dbo].[p_NewInstance]

    @instname varchar(100) = 'testinst3'

    AS

    BEGIN

    declare @installcmd varchar(4000)

    set @installcmd = '

    start /wait G:\SQL_Server_2005_Standard\Disk1\setup.exe /qn INSTANCENAME=' + @instname +

    ' ADDLOCAL=SQL_Engine,SQL_Data_Files

    SAPWD=verystrong

    INSTALLSQLDIR= "F:\Program Files\Microsoft SQL Server"

    INSTALLSQLDATADIR="E:\data\' + @instname + '"

    SQLBROWSERACCOUNT= "NT AUTHORITY\SYSTEM"

    SQLBROWSERPASSWORD=

    SQLACCOUNT="NT AUTHORITY\SYSTEM"

    SQLPASSWORD=

    AGTACCOUNT="NT AUTHORITY\SYSTEM"

    AGTPASSWORD=

    SQLBROWSERAUTOSTART=1

    SQLAUTOSTART=1

    AGTAUTOSTART=1

    SECURITYMODE=SQL

    SQLCOLLATION=SQL_Latin1_General_CP1_CI_AS

    DISABLENETWORKPROTOCOLS=0

    '

    select @installcmd

    exec xp_cmdshell @installcmd

    END

    Jimmy

    "I'm still learning the things i thought i knew!"
  • imSQrLy (4/24/2009)


    I have created a sproc that calls xp_cmdshell to install sql server. The full script(only posting the install part here) then does some other stuff like create data and log folders and updates the reg to point to these etc. The xp_cmdshell seems to time out on the install for lack of a better idea. But i don't really think thats it, as if i send a bad install command it never times out. So i was thinking permissions, so i changed the instance to run under my windows account with full admin (ya i know its not safe but this is dev machine 🙂 ) That didnt fix it.

    The sproc outputs the command args and if i copy and paste them into a cmd window sql server gets installed just fine.

    Long story short i am trying to create a single script to install and configure in detail all newly installed instances. I have everything else working in the full script excluding the install part.

    Anyone with some ideas let me know. You will have do adjust the script to point to correct drives and binaries for your environment. script below:

    USE [Admin]

    GO

    /****** Object: StoredProcedure [dbo].[p_NewInstance] Script Date: 04/24/2009 14:45:33 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    -- =============================================

    -- Author:

    -- Create date:

    -- Description:

    -- =============================================

    create PROCEDURE [dbo].[p_NewInstance]

    @instname varchar(100) = 'testinst3'

    AS

    BEGIN

    declare @installcmd varchar(4000)

    set @installcmd = '

    start /wait G:\SQL_Server_2005_Standard\Disk1\setup.exe /qn INSTANCENAME=' + @instname +

    ' ADDLOCAL=SQL_Engine,SQL_Data_Files

    SAPWD=verystrong

    INSTALLSQLDIR= "F:\Program Files\Microsoft SQL Server"

    INSTALLSQLDATADIR="E:\data\' + @instname + '"

    SQLBROWSERACCOUNT= "NT AUTHORITY\SYSTEM"

    SQLBROWSERPASSWORD=

    SQLACCOUNT="NT AUTHORITY\SYSTEM"

    SQLPASSWORD=

    AGTACCOUNT="NT AUTHORITY\SYSTEM"

    AGTPASSWORD=

    SQLBROWSERAUTOSTART=1

    SQLAUTOSTART=1

    AGTAUTOSTART=1

    SECURITYMODE=SQL

    SQLCOLLATION=SQL_Latin1_General_CP1_CI_AS

    DISABLENETWORKPROTOCOLS=0

    '

    select @installcmd

    exec xp_cmdshell @installcmd

    END

    I know it has been some time since you posted this problem, but if you haven't resolved it yet, please give this a try:

    set @installcmd = 'start /wait G:\SQL_Server_2005_Standard\Disk1\setup.exe /qn INSTANCENAME=' + @instname +

    ' ADDLOCAL=SQL_Engine,SQL_Data_Files' +

    ' SAPWD=verystrong' +

    ' INSTALLSQLDIR= "F:\Program Files\Microsoft SQL Server"' +

    ' INSTALLSQLDATADIR="E:\data\' + @instname + '" ' +

    ' SQLBROWSERACCOUNT= "NT AUTHORITY\SYSTEM"' +

    ' SQLBROWSERPASSWORD=' +

    ' SQLACCOUNT="NT AUTHORITY\SYSTEM"' +

    ' SQLPASSWORD=' +

    ' AGTACCOUNT="NT AUTHORITY\SYSTEM"' +

    ' AGTPASSWORD=' +

    ' SQLBROWSERAUTOSTART=1' +

    ' SQLAUTOSTART=1' +

    ' AGTAUTOSTART=1' +

    ' SECURITYMODE=SQL' +

    ' SQLCOLLATION=SQL_Latin1_General_CP1_CI_AS' +

    ' DISABLENETWORKPROTOCOLS=0'

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply