【发布时间】:2014-10-10 09:37:17
【问题描述】:
我使用 nologo 选项将cscript.exe 设置为我的默认脚本主机。因此在cmd.exe
正如预期的那样,我得到了:
> ftype jsfile
jsfile="C:\Windows\System32\CScript.exe" //nologo "%1" %*
> reg query HKCR\jsfile\Shell\Open\Command
HKEY_CLASSES_ROOT\jsfile\Shell\Open\Command
(Default) REG_EXPAND_SZ "C:\Windows\System32\CScript.exe" //nologo "%1" %*
> echo WScript.Echo("Test Echo"); > test.js
> test.js
Test Echo
但是,迁移到 Powershell:
> powershell -nologo
PS > .\test.js
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
Test Echo
CScript 似乎没有从 Powershell shell 获得//nologo。
我怎样才能解决这个问题?
更多用例
它也适用于:
PS > cscript.exe //nologo test.js
Test Echo
PS > cmd /c test.js
Test Echo
PS > cmd /c test
Test Echo
复制粘贴测试
有人认为这可能是一个错误。要检查它是否适用于您,您可以在具有提升权限的 PS 控制台中复制以下内容:
## Change the host to cscript nologo and store old setting
$jstype="Registry::HKEY_CLASSES_ROOT\jsfile\Shell\Open\Command"
$jsvalue=("`"$env:SystemRoot\System32\CScript.exe`"" + ' //nologo "%1" %*')
$old=(gp -Path $jstype )."(default)"
Set-Item -Path $jstype -value $jsvalue
## The output should be the same (i.e. nologo!)
echo 'WScript.Echo("Test Echo");' > test.js
cmd /c test
.\test.js
## Restore old settings
Set-Item -Path $jstype -value $old
cmd /c test 和 .\test.js 的输出是否相同?
【问题讨论】:
-
如果你运行
PS> cmd /c test.js它是否有效? -
嗯。为我工作。
-
@walidtoumi:是的;另请参阅问题更新。
-
@antonio: 可能是一个错误......你可以使用像这样的包装器
function execute-js ($file) { cmd /c $file }并像这样执行它execute-js -file file.js -
@walidtoumi:能否请您复制并粘贴我添加到问题中的测试并告诉我问题是否也适用于您?
标签: powershell jscript file-association wsh