Skip to main content
Disposition_Dev
Legend
November 6, 2018
Answered

VBS script to quit an external application?

  • November 6, 2018
  • 1 reply
  • 3938 views

I may be in need of a way to quit an external application during the execution of a .jsx script in illustrator. Specifically acrobat. I've written some code that saves the current document as a PDF, but I'm finding that on windows, an error presents itself when attempting to save a pdf that is already open in Acrobat.

Anybody with VBS experience have any advice to share? I've never written VBS and don't have a windows machine to test on.. so the more complete the advice the better.

Thanks in advance.

This topic has been closed for replies.
Correct answer CarlosCanto

I looked here for some examples

Close an application using VBScript - Stack Overflow

this one worked for me to close Reader on Windows 10

'attempt to quit Reader,

'Option Explicit 'all variables must be declared

Err.Clear

On Error Resume Next

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _

    ("Select * from Win32_Process Where Name = 'AcroRd32.exe'")

For Each objProcess in colProcessList

    objProcess.Terminate()

    If (Err.number <> 0) Then

                Err.Clear

    End If

Next

as with js, copy the script and paste it into a text editor and give it a vbs extension. Double click to execute or use file.execute() in your jsx

1 reply

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
November 8, 2018

I looked here for some examples

Close an application using VBScript - Stack Overflow

this one worked for me to close Reader on Windows 10

'attempt to quit Reader,

'Option Explicit 'all variables must be declared

Err.Clear

On Error Resume Next

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _

    ("Select * from Win32_Process Where Name = 'AcroRd32.exe'")

For Each objProcess in colProcessList

    objProcess.Terminate()

    If (Err.number <> 0) Then

                Err.Clear

    End If

Next

as with js, copy the script and paste it into a text editor and give it a vbs extension. Double click to execute or use file.execute() in your jsx

Disposition_Dev
Legend
November 8, 2018

awesome, thanks carlos!