Created
October 7, 2012 14:18
-
-
Save basilevs/3848511 to your computer and use it in GitHub Desktop.
HTA network drives mounting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>Сетевые диски</title> | |
| <meta http-equiv="x-ua-compatible" content="ie=9"> | |
| <hta:application | |
| id="gymlogin" | |
| applicationname="gymlogin" | |
| version="1" | |
| scroll="no" | |
| singleinstance="yes" | |
| </hta> | |
| </head> | |
| <script> | |
| if (!Array.prototype.indexOf) { | |
| Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { | |
| "use strict"; | |
| if (this == null) { | |
| throw new TypeError(); | |
| } | |
| var t = Object(this); | |
| var len = t.length >>> 0; | |
| if (len === 0) { | |
| return -1; | |
| } | |
| var n = 0; | |
| if (arguments.length > 1) { | |
| n = Number(arguments[1]); | |
| if (n != n) { // shortcut for verifying if it's NaN | |
| n = 0; | |
| } else if (n != 0 && n != Infinity && n != -Infinity) { | |
| n = (n > 0 || -1) * Math.floor(Math.abs(n)); | |
| } | |
| } | |
| if (n >= len) { | |
| return -1; | |
| } | |
| var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); | |
| for (; k < len; k++) { | |
| if (k in t && t[k] === searchElement) { | |
| return k; | |
| } | |
| } | |
| return -1; | |
| } | |
| } | |
| shell = new ActiveXObject("WScript.Shell"); | |
| fso = new ActiveXObject("Scripting.FileSystemObject"); | |
| function log(line ) { | |
| logArea.value += line+"\n"; | |
| } | |
| var cp866rus = [1026,160,1027,1038,8218,1118,1107,1032,8222,164,8230,1168,1088,1089,8224,166,8225,167,8364,1025,8240,169,1033,1028,8249,171,1034,172,1036,173,1035,174,1039,1031,1106,1072,8216,1073,8217,1074,8220,1075,8221,1076,8226,1077,8211,1078,8212,1079,152,1080,8482,1081,1113,1082,8250,1083,1114,1084,1116,1085,1115,1086,1119,1087]; | |
| var utf8rus = "АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя"; | |
| function fromCp866(input) { | |
| if (cp866rus.length != utf8rus.length) | |
| throw new Error("Length of cp866 aplhabet "+cp866rus.length+", utf-8: "+utf8rus.length); | |
| var i ; | |
| var rv=""; | |
| for (i=0; i < input.length; i++) { | |
| var code = input.charCodeAt(i); | |
| // log("Code:"+code); | |
| var pos = cp866rus.indexOf(code); | |
| // log("Pos:"+pos); | |
| if (pos != -1) | |
| code=utf8rus.charCodeAt(pos); | |
| rv+=String.fromCharCode(code); | |
| } | |
| return rv; | |
| } | |
| function execute(command) { | |
| log(shell.Exec(command).StdErr.ReadAll()); | |
| } | |
| function executeWithLog(command) { | |
| log(command); | |
| execute(command); | |
| } | |
| function getValueById(id) { | |
| return document.getElementById(id).value; | |
| } | |
| function connectDrive(login, password, letter, netpath) { | |
| var command = "net use "+letter+": " + netpath+" "+password+" /USER:GYM3\\"+login+" /PERSISTENT:NO"; | |
| log(command.replace(password, "***")); | |
| var e = shell.Exec(command); | |
| var errors=e.StdErr.ReadAll(); | |
| var code = e.ExitCode; | |
| log(fromCp866(errors)); | |
| if (errors.split("\n").length>1) { | |
| throw new Error("Не удалось подключить "+netpath); | |
| } | |
| } | |
| function removeDrives() { | |
| var command = "net use /D * /y"; | |
| executeWithLog(command); | |
| } | |
| function login() { | |
| logArea.value=""; | |
| var login = getValueById("login"); | |
| var password = getValueById("password"); | |
| try { | |
| removeDrives(); | |
| connectDrive(login, password, "H", "\\\\gym3.local\\"+login); | |
| connectDrive(login, password, "T", "\\\\gym3.local\\tmp"); | |
| connectDrive(login, password, "S", "\\\\gym3.local\\soft"); | |
| } catch(e) { | |
| alert(e.message); | |
| } | |
| // var cp866=fso.OpenTextFile("c:\\users\\гость\\Desktop\\cp866.txt",1).ReadAll() | |
| // var codes=[]; | |
| // for (i=0; i<cp866.length; i++) { | |
| // codes.push(cp866.charCodeAt(i)); | |
| // } | |
| // log(codes); | |
| // self.close() | |
| } | |
| </script> | |
| <body> | |
| <p> | |
| При системной ошибке 1219 следует удалить все сетевые диски, выйти из системы, войти обратно и повторить попытку. | |
| </p> | |
| Логин: <input type="text" id="login"><br> | |
| Пароль: <input type="password" id="password" onkeydown="if (event.keyCode == 13) login()"><br> | |
| <input type="button" value="Подключить" onClick="login()"> | |
| <input type="button" value="Отключить" onClick="removeDrives()"> | |
| <input type="button" value="Закрыть" onClick="self.close()"><br> | |
| Отчет:<br> | |
| <textarea rows="25" cols="80" id="log"></textarea><br> | |
| <script> | |
| logArea = document.getElementById("log"); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment