diff --git a/app/index.js b/app/index.js index 5efd091..154e6b3 100644 --- a/app/index.js +++ b/app/index.js @@ -18,7 +18,7 @@ var applications = []; var localApplications = []; var assign = function() { - SHELL.runWindow("cscript app.js shadow"); + SHELL.runVisibleWindow("cscript app.js shadow"); }; var pingtest = function() { diff --git a/lib/shell.js b/lib/shell.js index b7ada6a..88b78ba 100644 --- a/lib/shell.js +++ b/lib/shell.js @@ -20,6 +20,7 @@ var ShellObject = function() { this.workingDirectory = null; this.isElevated = false; this.isFork = false; + this.isVisibleWindow = false; this.create = function() { try { @@ -40,6 +41,11 @@ var ShellObject = function() { return this; }; + this.setVisibleWindow = function(visible) { + this.isVisibleWindow = visible; + return this; + }; + this.build = function(cmd) { if (typeof(cmd) === "string") { return cmd; @@ -90,21 +96,13 @@ var ShellObject = function() { var fork = (typeof(fork) !== "undefined") ? fork : true; var c = "%comspec% /q /c (" + this.build(cmd) + ")"; console.info("ShellObject.run() -> " + c); - this.interface.Run(c, 0, !fork); - }; - - this.runWindow = function(cmd, fork) { - var fork = (typeof(fork) !== "undefined") ? fork : true; - var c = "%comspec% /q /c (" + this.build(cmd) + ")"; - console.info("ShellObject.runWindow() -> " + c); - this.interface.Run(c, 1, !fork); + this.interface.Run(c, (!this.isVisibleWindow ? 0 : 1), !fork); }; this.runAs = function(FN, args) { - var c = FN + " " + args.join(' '); var oShell = CreateObject("Shell.Application"); - console.info("ShellObject.runAs() -> " + c); - oShell.shellExecute(FN, args, null, "runas", 0); + console.info("ShellObject.runAs() -> " + FN); + oShell.shellExecute(FN, args, this.workingDirectory, "runas", (!this.isVisibleWindow ? 0 : 1)); return oShell; }; @@ -143,8 +141,8 @@ exports.run = function(cmd, fork) { return (new ShellObject()).run(cmd, fork); }; -exports.runWindow = function(cmd, fork) { - return (new ShellObject()).runWindow(cmd, fork); +exports.runVisibleWindow = function(cmd, fork) { + return (new ShellObject()).setVisibleWindow(true).run(cmd, fork); } exports.createProcess = function(cmd, workingDirectory) { @@ -162,6 +160,6 @@ exports.createDesktopIcon = function(filename, workingDirectory) { return (new ShellObject()).createDesktopIcon(filename, workingDirectory); }; -exports.VERSIONINFO = "Shell Lib (shell.js) version 0.1"; +exports.VERSIONINFO = "Shell interface (shell.js) version 0.2"; exports.global = global; exports.require = global.require;