Reputation: 8586
I'm trying to open a .exe application from WinJS but I get an error, this is my code:
var comando = "C:\\Program%20Files%20(x86)\\Windows%20Media%20Player\\wmplayer.exe";
var oShell = new ActiveXObject("Shell.Application");
//var commandtoRun = "C:\\Windows\\notepad.exe";
oShell.ShellExecute(comando, "", "", "open", "1");
but I get an error...
0x800A01AD - Runtime Error in JavaScript: Automation server can not create object
any help I'll appreciate
Upvotes: 4
Views: 665
Reputation: 4386
You can kind of pull it off if you know of a specific file type association. If you package a file with a file extension associated with the target app, you can tell your WinJS app to open it and it will trigger the associated app to open the file. Some obvious extensions are excluded, like .exe, .msi, etc.
This code will try to open a .txt file in whatever app is associated with that extension:
var txtFile = "Assets\\myFile.txt";
Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(txtFile).then(
function (file) {
Windows.System.Launcher.launchFileAsync(file).then(
function (success) {
if (success) {
// File launched
} else {
// File launch failed
}
});
});
It's not a perfect solution, as you cannot target a specific application, you can only trigger whatever app the user has associated with that file type, but it might be useful for some circumstances.
Upvotes: 1
Reputation: 10310
I'm afraid it's not possible to use ActiveX controls in JavaScript Windows Store apps this way. Windows Store apps are isolated from the system and cannot run arbitrary code from outside the app container. It would be too easy to insert malware that way.
Upvotes: 2