

Set objShell = CreateObject(“Wscript.Shell”) For example, here’s a simple little HTA that creates the Wscript.Shell object and then runs Notepad.exe (opening the file C:\Scripts\Test.txt along the way): There are other WSH objects that you can create, including the Shell object. Notice that we didn’t create the Wscript object instead, it was created for us when we invoked Windows Script Host.īut that’s just for the Wscript object. That’s why this is a perfectly valid script: Wscript.Echo “Hey.”

Instead, the Wscript object is automatically created – and only created – when you run Windows Script Host (that is, Wscript.exe or Cscript.exe). This is a point that often creates confusion: because you can’t use certain commands – such as Wscript.Echo and Wscript.Sleep – within an HTA people assume you can’t use any WSH commands in an HTA.įirst things first: why can’t you use Wscript.Echo and Wscript.Sleep in an HTA? Well, those methods are properties of the Wscript object, and you can’t create an instance of the Wscript object. Before we do that, however, we should note that you actually can use the Wscript.Shell object within an HTA. Yes, we do know of an alternative to the Wscript.Shell command that will work in HTAs, and we’ll show you that in a minute. Hey, Scripting Guy! Is there an alternative to the Wscript.Shell command for HTAs? I need to run an application and specify the file to open.
