Declare @PortNumber VarChar(7)
Exec Xp_RegRead
@RootKey='HKEY_LOCAL_MACHINE',
@Key='Software\Microsoft\Microsoft Sql Server\SQLEXPRESS\MSSQLServer\SuperSocketNetLib\Tcp',
@Value_Name='TcpPort',
@Value=@PortNumber OutPut
Print 'Port Number:'
Print @PortNumber
When you execute this you will get a problem to enable XP_CMDshell.You can enable by this.Read the article at:
Enabling xp_cmdshell in SQL Server 2005