How to create a batch file using SQL

The output of this query can be used to create a batch file to execute service control to fix BITS service.

  • Open  SQL  Server Management Studio and paste this query.
  • Edit it as you need.
  • Execute the query
  • Save the result panel as fixbits.bat
  • Finally open a DOS Prompt
  • Make sure that sc.exe is located within the path.
  • Run fixbits.bat

 

 

select

‘sc \\’+CS.Name0 +‘ sdset bits “bla bla”‘

from

      dbo.v_GS_SERVICE S left outer join dbo.v_GS_Computer_system cs on CS.ResourceID = S.ResourceID

where

      (displayname0 = ‘Background Intelligent Transfer Service’) and

      ( State0 != ‘Running’ or isnull(State0, ‘NULL’) = ‘NULL’)

 

Leave a Reply

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