I am facing an issue while trying to open an image file from a Silverlight app in Windows 10 using WScript.Shell.
The code is as follows.
try
{
dynamic shell = AutomationFactory.CreateObject("WScript.Shell");
shell.Run(@"C:\temp\X.jpg");
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace);
}
This piece of code works perfectly fine when the default application is set to 'Photos' / 'Internet Explorer' in Windows 10 'Default Apps' settings.
However, when the default app is set to 'Paint', I get an exception "No application is associated with the specified file for this operation. (Exception from HRESULT: 0x80070483)"
Please note that when I try to double click on the same image in Windows explorer, it opens up in Paint application without errors.
Why does this happen? Please help.
If you do not specify a script or any script arguments, wscript.exe displays the Windows Script Host Settings dialog box, which you can use to set global scripting properties for all scripts that wscript.exe runs on the local computer. The /t parameter prevents excessive running of scripts by setting a timer.
CreateObject instantiates an instance of an outside application into the VBscript runtime. Basically, in the case of wscript. shell, it creates an object that is an instance of the windows shell allowing you to run commands against the windows shell from within your VBScript.
The Run method creates a new process and runs the command specified by strCommand. The optional parameter intWindowStyle is used to set the window style of the program being run. If the optional parameter bWaitOnReturn is set to True (default is False), then Run will return the return value returned by strCommand.
WScript.Shell
Objectin the example below, we reference both the program and the file we want to run with 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With