【问题标题】:WScript.Shell Run gives "No application is associated with the specified file for this operation." when opening images.WScript.Shell Run 给出“没有应用程序与此操作的指定文件关联。”打开图像时。
【发布时间】:2016-10-28 09:51:09
【问题描述】:

我在尝试使用 WScript.Shell 从 Windows 10 中的 Silverlight 应用程序打开图像文件时遇到问题。

代码如下。

        try
        {
            dynamic shell = AutomationFactory.CreateObject("WScript.Shell");
            shell.Run(@"C:\temp\X.jpg");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.StackTrace);
        }

当默认应用程序在 Windows 10“默认应用程序”设置中设置为“照片”/“Internet Explorer”时,这段代码可以正常工作。

但是,当默认应用程序设置为“绘画”时,我得到一个异常 "没有应用程序与此操作的指定文件关联。(HRESULT 异常:0x80070483)"

请注意,当我尝试在 Windows 资源管理器中双击同一图像时,它会在“画图”应用程序中打开而没有错误。

为什么会这样? 请帮忙。

【问题讨论】:

  • 这可能是 x64 与 x86 的问题吗?您的 shell 开始使用其中任何一个。当引用 IE 时,它会选择匹配的版本(幸运?),当引用 Paint 时,它是不匹配的,因此它看不到它。
  • 尝试@"start C:\temp\X.jpg" - 抱歉现在无法测试

标签: silverlight-5.0 wsh


【解决方案1】:

问题

  • Windows 脚本主机未运行已知文件类型的所需应用程序

解决方案

  • 明确指定所需的应用程序并使用WScript.Shell Object 运行

示例

  • 在下面的示例中,我们使用strRunLine引用了我们要运行的程序和文件

    <?xml version="1.0"?>
    <package>
    <job id="default">
        <script language="jscript">
        <![CDATA[
            // save to demo_runpaint.wsf
            var WshShell        =   new ActiveXObject("Wscript.Shell");
            var strRunLine      =   "";
    
            strRunLine  = "mspaint.exe C:/path/to/capture.png";
            WshShell.Run( strRunLine );
        ]]>
        </script>
    </job>
    </package>
    

陷阱

  • 所需的程序必须在您的系统路径中,否则您必须明确指定应用程序的完整路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多