Wednesday, April 4, 2012

How to start a VBS file using AutoLISP

If you in AutoCAD want to start a VBScript file with AutoLISP here are three ways where the variable app holds the full path to the VBS file:

(startapp "WSCRIPT.EXE" (strcat "\"" app "\""))

(command "START" app)

(if (setq WScript (vlax-get-or-create-object "WScript.Shell"))
  (vl-catch-all-apply 'vlax-invoke-method (list WScript "Run" app 1 :vlax-true))
)

If the START command is used you will quickly see the AutoCAD Shell so I prefer to use the startapp function.

If the path contains spaces like (C:\\Folder A\\test.vbs) the startapp function must have the path with double quotes like the snippet above, otherwise the Windows Script Host will show this error: There is no file extension in "C:\Folder".

Some of this works with starting or running other files (EXE, BAT, CMD,…) or open files in their associated application. See also how to Start a Windows application within AutoCAD.


Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner