diff --git a/lib/powershell.js b/lib/powershell.js index ec54327..a3bfb50 100644 --- a/lib/powershell.js +++ b/lib/powershell.js @@ -20,37 +20,37 @@ exports.addslashes = function(string) { }; exports.execScript = function(scriptName, args) { - var arguments = []; + var commandOptions = []; - arguments.push("powershell.exe"); - arguments.push("-NoProfile"); - arguments.push("-ExecutionPolicy"); - arguments.push("ByPass"); - arguments.push("-nologo") - arguments.push("-file"); - arguments.push(scriptName + ".ps1"); + commandOptions.push("powershell.exe"); + commandOptions.push("-NoProfile"); + commandOptions.push("-ExecutionPolicy"); + commandOptions.push("ByPass"); + commandOptions.push("-nologo") + commandOptions.push("-file"); + commandOptions.push(scriptName + ".ps1"); if(typeof(args) !== "undefined") { for(var i in args) { - arguments.push(args[i]); + commandOptions.push(args[i]); } } - return SHELL.exec(arguments.join(' ')); + return SHELL.exec(commandOptions.join(' ')); }; exports.execCommand = function(command) { - var arguments = []; + var commandOptions = []; - arguments.push("powershell.exe"); - arguments.push("-NoProfile"); - arguments.push("-ExecutionPolicy"); - arguments.push("ByPass"); - arguments.push("-nologo") - arguments.push("-Command"); - arguments.push("\"& {"); - arguments.push(exports.addslashes(command)); - arguments.push("}\""); + commandOptions.push("powershell.exe"); + commandOptions.push("-NoProfile"); + commandOptions.push("-ExecutionPolicy"); + commandOptions.push("ByPass"); + commandOptions.push("-nologo") + commandOptions.push("-Command"); + commandOptions.push("\"& {"); + commandOptions.push(exports.addslashes(command)); + commandOptions.push("}\""); - return SHELL.exec(arguments.join(' ')); + return SHELL.exec(commandOptions.join(' ')); }; diff --git a/uriloader.js b/uriloader.js index a25f557..bef645b 100644 --- a/uriloader.js +++ b/uriloader.js @@ -22,40 +22,47 @@ return { if(pos < 0) { console.log("Not vaild URI"); } else { - var queryString = uri.substring(pos + 4); - var query = this.parseQuery(queryString); - var application = query['application']; - var argument = query['argument']; - var filename; + var commandOptions = [], + queryString = uri.substring(pos + 4), + query = this.parseQuery(queryString); - switch(application) { + if(!query.application) { + query.application = ""; + } + + switch(query.application) { case "app": - filename = "app.hta"; + commandOptions.push("app.hta"); break; case "mscalc": - filename = "calc"; + commandOptions.push("calc"); break; case "msie": - filename = "%PROGRAMFILES%\\Internet Explorer\\iexplore.exe"; + commandOptions.push("\"%PROGRAMFILES%\\Internet Explorer\\iexplore.exe\""); + commandOptions.push("https://github.com/gnh1201/welsonjs"); break; case "msexcel": - filename = "%PROGRAMFILES%\\Microsoft Office\\Office15\\EXCEL.EXE"; + commandOptions.push("\"%PROGRAMFILES%\\Microsoft Office\\Office15\\EXCEL.EXE\""); break; case "mspowerpoint": - filename = "%PROGRAMFILES%\\Microsoft Office\\Office15\\POWERPNT.EXE"; + commandOptions.push("\"%PROGRAMFILES%\\Microsoft Office\\Office15\\POWERPNT.EXE\""); break; case "msword": - filename = "%PROGRAMFILES%\\Microsoft Office\\Office15\\WINWORD.EXE"; + commandOptions.push("\"%PROGRAMFILES%\\Microsoft Office\\Office15\\WINWORD.EXE\""); break; case "msaccess": - filename = "%PROGRAMFILES%\\Microsoft Office\\Office15\\MSACCESS.EXE"; + commandOptions.push("\"%PROGRAMFILES%\\Microsoft Office\\Office15\\MSACCESS.EXE\""); break; dafault: console.log("Unknown application"); break; } - SHELL.run("\"" + filename + "\"" + " " + argument); + if(typeof(query.argument) !== "undefined") { + commandOptions.push(query.argument); + } + + SHELL.run(commandOptions.join(' ')); } } }