VBScript(WSH):未通过文件关联传递的参数

时间:2012-02-04 12:00:33

标签: vbscript registry file-type wsh

更新

我修改了hkcr\vbsfile\shell,因此它反映了hkcr\vbsfile\shell。使用VBScript的文件类型关联时,参数仍然不起作用。

我想知道这些注册表项是否会失败:

:: 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.

即使以管理员身份启动HKEY_CLASSES_ROOT\VBS,我也无法重命名HKEY_CLASSES_ROOT\VBScriptregedit

:: 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

原帖

当通过filetype关联而不是cscript.exewscript.exe调用时,脚本不会通过命令行接收传递给它们的参数。

:: 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" %*

看起来这个文件类型关联将所有参数传递给脚本。但也许它没有被使用?我该如何追踪?以下是来自注册表的更多信息:

:: 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 &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" %*

这是Windows 7 Pro 64,如果它很重要(我不认为它)。还有一件事,参数在所有三种情况下都能正常工作(cscript.exewscript.exe,文件类型关联),使用JScript引擎和以下脚本:

var argc = WScript.Arguments.Length;
WScript.Echo(argc);
for (var i = 0; i < argc; i++)
        WScript.Echo( WScript.Arguments(i) );

设定:

:: 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" %*

1 个答案:

答案 0 :(得分:1)

解决方案

搜索了cscript的注册表。我的注册表中有以下密钥:

:: reg query HKEY_CLASSES_ROOT\Applications\cscript.exe /s
...
HKEY_CLASSES_ROOT\Applications\cscript.exe\shell\open\command
    (Standard)    REG_SZ    "C:\Windows\System32\cscript.exe" "%1"

一旦我将其修复为"C:\Windows\System32\cscript.exe" "%1" %*,参数就开始使用文件关联正确处理VBScript。 (无论如何,休息还可以。)