Jump to content

aodennison

Member
  • Posts

    1
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    United States

About aodennison

Profile Information

  • OS
    Windows 8 x64

aodennison's Achievements

0

Reputation

  1. I came up with a trick similar to the UNIX convention of starting script files with the name of the shell used to interpret the script. The difference is that this is built into how UNIX starts up files, while cmd/DOS has no such convention. I create one file called: 'cscript.cmd __________________________________ @cscript.exe //E:VBScript //NoLogo %* __________________________________ The name has to start with a single quote, it has to be a batch/.cmd file, and it should be on your PATH. Next I create my vbscript file, and call it something like HelloWorld.cmd. and put a special line at the top: 'cScript "%~f0" %* followed by my vbscript. So it looks like this: HelloWorld.cmd __________________________________________ 'cScript "%~f0" %* WScript.Echo "Hello World!!" For Each arg in WScript.Arguments.Unnamed WScript.Echo "Arg(" & count & ") = " & arg Next __________________________________________ Why It Works 1.) Cmd reads HelloWorld.cmd and executes 'cscript.cmd, passing along HelloWorld.cmd as the first argument. 2.) Cmd executes 'cscript.cmd. It starts cscript passing it HelloWorld.cmd. 3. Cscript starts reading HelloWorld.cmd, and skips the first line since it starts with a single quote, a comment. 4.) Cscript goes on to execute the file as usual. 5.) When Cscript exits, cmd does not resume reading HelloWorld.cmd, because cmd has this quirk where if you execute a cmd file without using CALL, it never returns. Note with and exe, cmd resumes at the next line. Because of this cmd does not attempt to process the rest of the file, which is all vbscript. In short it works because, the first line is interpreted as cmd file name, and then as a vbscript comment. And also because cmd never tries to read the second line which is vbscript. There are probably issues with arguments that include special characters and quotes, but in practice it has not been a problem for me. I have used this same trick with scripts for Beyond Compare, and also for autohotkey. If you download the attachments, just rename the files to end with .cmd. Some virus checkers don't like cmd files. 'cscript.cmd.txt HelloWorld.vbs.cmd.txt
×
×
  • Create New...