SQL Server: Running VB Script From TSQL
Posted by Prashant on August 3, 2010
In this post we will see if we can run a VB Script from SQL Server. Yes, SQL Server allows to run external Scripts. So, here is the process how to run a VB Script from TSQL Code.
Well to test this lets first create a sample VB Script which will just display a message.
Dim VarSetMessage VarSetMessage = "Running VB Script from SQL Server..." 'Display message WScript.Echo VarSetMessage
Save it as “myMsg.vbs” on “C:\” drive of your machine. Okey, before running this script from SQL Server, lets see how to run it from Command Prompt. To do this:
Start => Run => cmd => ENTER Type Cscript C:\myMsg.vbs => ENTER
(Refer below image for result)
Now to run the VB Script from SQL Server just run the same command line we tested above using xp_cmdshell from SQL Server.
EXEC XP_CMDSHELL 'CScript C:\myMsg.vbs'
and we are done !!!
Note: You may need to configure xp_cmdshell if not configured before.