title: Arguments not passed through file association
body: <h2>Update</h2>
  
  <p>I edited <code>hkcr\vbsfile\shell</code> so it mirrors <code>hkcr\vbsfile\shell</code>. Arguments still don't work when using the filetype association for VBScript.</p>
  
  <p>I wonder whether these registry keys make it fail:</p>
  
  <pre><code>:: reg query hkcr /f vbs*
  
  HKEY_CLASSES_ROOT\.vbs
  ...
  HKEY_CLASSES_ROOT\VBS
  HKEY_CLASSES_ROOT\VBS Author
  HKEY_CLASSES_ROOT\VBScript
  HKEY_CLASSES_ROOT\VBScript Author
  HKEY_CLASSES_ROOT\VBScript.Encode
  HKEY_CLASSES_ROOT\VBScript.RegExp
  HKEY_CLASSES_ROOT\VBSFile
  HKEY_CLASSES_ROOT\VBSFile.HostEncode
  Suchvorgang abgeschlossen: 21 übereinstimmende Zeichenfolge(n) gefunden.
  </code></pre>
  
  <p>I cannot rename <code>HKEY_CLASSES_ROOT\VBS</code> or <code>HKEY_CLASSES_ROOT\VBScript</code>, not even when starting <code>regedit</code> as Administrator.</p>
  
  <pre><code>:: reg query hkcr\vbs /s
  
  HKEY_CLASSES_ROOT\vbs\CLSID
      (Standard)    REG_SZ    {B54F3741-5B07-11cf-A4B0-00AA004A55E8}
  
  HKEY_CLASSES_ROOT\vbs\OLEScript
      (Standard)    REG_NONE
  
  
  :: reg query hkcr\vbscript /s
  
  HKEY_CLASSES_ROOT\vbscript
      (Standard)    REG_SZ    VB Script Language
  
  HKEY_CLASSES_ROOT\vbscript\CLSID
      (Standard)    REG_SZ    {B54F3741-5B07-11cf-A4B0-00AA004A55E8}
  
  HKEY_CLASSES_ROOT\vbscript\OLEScript
      (Standard)    REG_NONE
  
  
  :: reg query hkcr\clsid\{B54F3741-5B07-11cf-A4B0-00AA004A55E8} /s
  
  HKEY_CLASSES_ROOT\clsid\{B54F3741-5B07-11cf-A4B0-00AA004A55E8}
      (Standard)    REG_SZ    VB Script Language
  
  HKEY_CLASSES_ROOT\clsid\{B54F3741-5B07-11cf-A4B0-00AA004A55E8}\
    Implemented Categories
  
  HKEY_CLASSES_ROOT\clsid\{B54F3741-5B07-11cf-A4B0-00AA004A55E8}\
    Implemented Categories\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}
      (Standard)    REG_NONE    
  
  HKEY_CLASSES_ROOT\clsid\{B54F3741-5B07-11cf-A4B0-00AA004A55E8}\
    Implemented Categories\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}
      (Standard)    REG_NONE    
  
  HKEY_CLASSES_ROOT\clsid\{B54F3741-5B07-11cf-A4B0-00AA004A55E8}\InprocServer32
      (Standard)    REG_SZ    C:\Windows\SysWOW64\vbscript.dll
      ThreadingModel    REG_SZ    Both
  
  HKEY_CLASSES_ROOT\clsid\{B54F3741-5B07-11cf-A4B0-00AA004A55E8}\OLEScript
      (Standard)    REG_NONE    
  
  HKEY_CLASSES_ROOT\clsid\{B54F3741-5B07-11cf-A4B0-00AA004A55E8}\ProgID
      (Standard)    REG_SZ    VBScript
  </code></pre>
  
  <h2>Original Post</h2>
  
  <p>Scripts do not receive arguments passed to them via the command line when invoked via the filetype association instead of via <code>cscript.exe</code> or <code>wscript.exe</code>.</p>
  
  <pre><code>:: type args.vbs
  Option Explicit
  WScript.Echo WScript.Arguments.Count
  Dim arg
  For Each arg In WScript.Arguments
          WScript.Echo arg
  Next
  
  :: cscript args.vbs eins zwei drei
  3
  eins
  zwei
  drei
  
  :: wscript args.vbs eins zwei drei
  :: : same thing via the MessageBox
  
  :: args.vbs eins zwei drei
  0
  
  :: : Why is that?
  :: assoc .vbs
  .vbs=VBSFile
  
  :: ftype VBSFile
  VBSFile="%SystemRoot%\System32\WScript.exe" "%1" %*
  </code></pre>
  
  <p>It looks like this filetype association passes all arguments to the script. But maybe it isn't used? How can I track this down? Here's more info from the registry:</p>
  
  <pre><code>:: reg query hkcr\.vbs
  
  HKEY_CLASSES_ROOT\.vbs
      (Standard)    REG_SZ    VBSFile
  
  HKEY_CLASSES_ROOT\.vbs\PersistentHandler
  
  :: reg query hkcr\VBSFile\Shell\Open /s
  
  HKEY_CLASSES_ROOT\VBSFile\Shell\Open\Command
      (Standard)    REG_EXPAND_SZ    "%SystemRoot%\System32\WScript.exe" "%1" %*
  
  
  :: reg query hkcr\VBSFile\Shell\Open2 /s
  
  HKEY_CLASSES_ROOT\VBSFile\Shell\Open2
      (Standard)    REG_EXPAND_SZ    Open &amp;with Command Prompt
      MUIVerb    REG_EXPAND_SZ    @%SystemRoot%\System32\wshext.dll,-4511
  
  HKEY_CLASSES_ROOT\VBSFile\Shell\Open2\Command
      (Standard)    REG_EXPAND_SZ    "%SystemRoot%\System32\CScript.exe" "%1" %*
  </code></pre>
  
  <p>This is Windows 7 Pro 64, if it matters (which I don't think it does). One more thing, arguments work correctly in all three cases (<code>cscript.exe</code>, <code>wscript.exe</code>, filetype association) using the JScript engine with the following script:</p>
  
  <pre><code>var argc = WScript.Arguments.Length;
  WScript.Echo(argc);
  for (var i = 0; i &lt; argc; i++)
          WScript.Echo( WScript.Arguments(i) );
  </code></pre>
  
  <p>Settings:</p>
  
  <pre><code>:: assoc .js
  .js=JSFile
  
  :: ftype JSFile
  JSFile=C:\Windows\System32\WScript.exe "%1" %*
  
  :: reg query hkcr\jsfile\shell\open\command
  
  HKEY_CLASSES_ROOT\jsfile\shell\open\command
      (Standard)    REG_SZ    C:\Windows\System32\WScript.exe "%1" %*
  
  
  :: reg query hkcr\jsfile\shell\open2\command
  
  HKEY_CLASSES_ROOT\jsfile\shell\open2\command
      (Standard)    REG_SZ    C:\Windows\System32\CScript.exe "%1" %*
  </code></pre>