0

I would like to create a SQL job that will close any excel processes opened. I've created a VB Script that works on double-click. I've tried

wscript C:\Apps\DestroyExcel.vbs

using type CmdExec. How can I execute it form SQL to schedule the job to run?

Dim objXL
On Error Resume Next
Set objXL = GetObject(, "Excel.Application")

If Not TypeName(objXL) = "Empty" Then
    objXL.quit
Else
    msgbox "Excel Not Running."
End If
Chait
  • 1,052
  • 2
  • 18
  • 30
g_shockTan
  • 325
  • 2
  • 8
  • 15

1 Answers1

0

In SSMS:

  1. Go to SQL Server Agent
  2. Right-click "Jobs" --> New Job
  3. Enter info
  4. In the steps section, click New
  5. For the Type, choose Operating Sytem (CmdExex)
  6. For the command, type: cscript C:\myscript.vbs
  7. Set your schedule
  8. Press OK

I believe that should do it.

Joseph
  • 5,070
  • 1
  • 25
  • 26
  • I've tried that option. It executes successfully with no errors, but Excel is still open. Maybe I should try Master.XP_CMDSHELL – g_shockTan Feb 06 '13 at 17:28
  • @g_shockTan that's interesting. maybe it's a permissions thing? I think the SQL job runs from the SQL Server agent by default which might not have sufficient permission to run the vbs script...hmmmm – Joseph Feb 06 '13 at 17:51
  • I executed it in cmd prompt and works using cscript c:\apps\destroyexcel.vbs enter. It closed all excel process. – g_shockTan Feb 06 '13 at 18:10
  • @g_shockTan it has to be a permissions issue then. the SQL Server Agent doesn't have enough privileges to execute the statements in the vbscript. let me see what i can figure out – Joseph Feb 06 '13 at 19:21
  • @g_shockTan after a lot of digging, i'm at a complete loss :( I cannot, for the life of me, get this to work on my PC. I tried a bunch of things (batch files, new users, proxies with credentials) but ultimately I can't get it to work. I would love to find out how you or anyone else solves this problem. sorry g_shockTan – Joseph Feb 06 '13 at 21:13