silverlight-5.0 - 打开图像时,WScript.Shell Run 给出 "No application is associated with the specified file for this operation."。

标签 silverlight-5.0 wsh

我在尝试使用 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”时,这段代码可以正常工作。

但是,当默认应用程序设置为“Paint”时,出现异常
“没有应用程序与此操作的指定文件相关联。(来自 HRESULT 的异常:0x80070483)”

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

为什么会发生这种情况?
请帮忙。

最佳答案

问题

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

  • 解决方案
  • 明确指定所需的应用程序并使用 WScript.Shell 运行对象

  • 例子
  • 在下面的示例中,我们同时引用了要使用 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>
    

  • 陷阱
  • 所需的程序必须在您的系统路径中,否则您必须明确指定应用程序的完整路径。
  • 关于silverlight-5.0 - 打开图像时,WScript.Shell Run 给出 "No application is associated with the specified file for this operation."。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40302488/

    相关文章:

    javascript - hta/javascript 如何使用相对路径执行应用程序

    vbscript - 使用 CopyHere 写入文件而不使用 WScript.Sleep

    windows - wscript 和 cscript 之间的区别

    vbscript - 我可以在 vbscript WSH 脚本中获取环境变量吗?

    json - cscript jscript JSON

    c# - 设置 IsEnabled = false silverlight 中的按钮

    silverlight-5.0 - 如何从 Silverlight 应用程序在新浏览器中打开 URL

    Silverlight 5 硬件加速

    silverlight - 如何在 Silverlight 中为 TextBox 设置行为样式?

    silverlight-5.0 - 银光 : disable copy/paste/cut operations on textbox