└── fw.js /fw.js: -------------------------------------------------------------------------------- 1 | Function.prototype.GetResource = function (ResourceName) 2 | { 3 | if (!this.Resources) 4 | { 5 | var UnNamedResourceIndex = 0, _this = this; 6 | this.Resources = {}; 7 | 8 | function f(match, resType, Content) 9 | { 10 | _this.Resources[(resType=="[[")?UnNamedResourceIndex++:resType.slice(1,-1)] = Content; 11 | } 12 | this.toString().replace(/\/\*(\[(?:[^\[]+)?\[)((?:[\r\n]|.)*?)\]\]\*\//gi, f); 13 | } 14 | 15 | return this.Resources[ResourceName]; 16 | } 17 | 18 | function GetResource(ResourceName) 19 | { 20 | return arguments.callee.caller.GetResource(ResourceName); 21 | } 22 | 23 | Enumerator.prototype.toArray = function () 24 | { 25 | var Result = []; 26 | for (;!this.atEnd();this.moveNext()) 27 | Result.push(this.item()) 28 | return Result; 29 | } 30 | 31 | Enumerator.prototype.forEach = function (action, that /*opt*/) 32 | { 33 | this.toArray().forEach(action, that); 34 | } 35 | 36 | // Add ECMA262-5 method binding if not supported natively 37 | // 38 | if (!('bind' in Function.prototype)) { 39 | Function.prototype.bind= function(owner) { 40 | var that= this; 41 | if (arguments.length<=1) { 42 | return function() { 43 | return that.apply(owner, arguments); 44 | }; 45 | } else { 46 | var args= Array.prototype.slice.call(arguments, 1); 47 | return function() { 48 | return that.apply(owner, arguments.length===0? args : args.concat(Array.prototype.slice.call(arguments))); 49 | }; 50 | } 51 | }; 52 | } 53 | 54 | // Add ECMA262-5 string trim if not supported natively 55 | // 56 | if (!('trim' in String.prototype)) { 57 | String.prototype.trim= function() { 58 | return this.replace(/^\s+/, '').replace(/\s+$/, ''); 59 | }; 60 | } 61 | 62 | // Add ECMA262-5 Array methods if not supported natively 63 | // 64 | if (!('indexOf' in Array.prototype)) { 65 | Array.prototype.indexOf= function(find, i /*opt*/) { 66 | if (i===undefined) i= 0; 67 | if (i<0) i+= this.length; 68 | if (i<0) i= 0; 69 | for (var n= this.length; ithis.length-1) i= this.length-1; 81 | for (i++; i-->0;) /* i++ because from-argument is sadly inclusive */ 82 | // if (i in this && this[i]===find) 83 | if (this[i]===find) 84 | return i; 85 | return -1; 86 | }; 87 | } 88 | 89 | if (!('forEach' in Array.prototype)) { 90 | Array.prototype.forEach= function(action, that /*opt*/) { 91 | for (var i= 0, n= this.length; i0) 713 | for (var i=0, l=Proc.length; i0) return Proc[0].ProcessId; 742 | return 0; 743 | } catch(e) { 744 | return 0; 745 | } 746 | } 747 | 748 | try { 749 | var Proc = WMIQuery("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2", "SELECT * FROM Win32_Process WHERE Name='"+ProcName+"'"); 750 | if (Proc.length>0) return Proc[0].ProcessId; 751 | return 0; 752 | } catch(e) { 753 | return 0; 754 | } 755 | } 756 | //MsgBox(ProcessExists("notepad.exe")); 757 | //Exit(); 758 | 759 | //Pauses script execution until a given process exists. 760 | function ProcessWait(process, timeout) 761 | //process The name of the process to check. 762 | //timeout [optional] Specifies how long to wait (in seconds). Default is to wait indefinitely. 763 | { 764 | if (!process) return 0; 765 | timeout = timeout || 0; 766 | var time_tmp=0, pid=0; 767 | while (pid=ProcessExists(process)) 768 | { 769 | Sleep(250); 770 | if (timeout!=0 && time_tmp>=timeout) break; else time_tmp+=0.250; 771 | } 772 | return pid; 773 | } 774 | //MsgBox(ProcessWait("notepad.exe")); 775 | //Exit(); 776 | 777 | //Pauses script execution until a given process does not exist. 778 | function ProcessWaitClose(process, timeout) 779 | //process The name of the process to check. 780 | //timeout [optional] Specifies how long to wait (in seconds). Default is to wait indefinitely. 781 | { 782 | timeout = timeout || 0; 783 | var time_tmp=0, pid=0; 784 | while (!(pid=ProcessExists(process))) 785 | { 786 | Sleep(250); 787 | if (timeout!=0 && time_tmp>=timeout) break; else time_tmp+=0.250; 788 | } 789 | return pid; 790 | } 791 | //MsgBox(ProcessWaitClose("notepad.exe")); 792 | //Exit(); 793 | 794 | // Get process path by pid 795 | function ProcessPath(pid) 796 | { 797 | var Proc = WMIQuery("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2", "SELECT * FROM Win32_Process WHERE ProcessId='"+pid+"'"); 798 | if (Proc[0]) return Proc[0].ExecutablePath; 799 | return ""; 800 | } 801 | //MsgBox(ProcessPath(GetPID())); 802 | //Exit(); 803 | 804 | // File, Directory and Disk Managment 805 | 806 | //DirCopy Copies a directory and all sub-directories and files (Similar to xcopy). 807 | function DirCopy(SourceDir, DestDir, flag) 808 | { 809 | SourceDir = WshShell.ExpandEnvironmentStrings(SourceDir); 810 | CreateDir(DestDir); 811 | 812 | flag = flag || 0; 813 | FSO.CopyFolder(SourceDir, DestDir, flag); 814 | return 1; 815 | } 816 | 817 | //DirCreate Creates a directory/folder. 818 | function CreateDir(Path) 819 | { 820 | function __FolderCreate(FolderPath) 821 | { 822 | if (!fso.FolderExists(FolderPath)) 823 | { 824 | __FolderCreate(fso.GetParentFolderName(FolderPath)); 825 | fso.CreateFolder(FolderPath); 826 | } 827 | } 828 | 829 | Path = WshShell.ExpandEnvironmentStrings(Path); 830 | __FolderCreate(Path); 831 | return 1; 832 | } 833 | 834 | //FileDelete Delete one or more files. (принудительное удаление. принимает как массивы файлов, так и просто путь) поддерживает удаление по маске. 835 | function FileDelete(Path) 836 | { 837 | if (/Array/i.test(Path.constructor+"")) 838 | { 839 | for (var i=0, l=Path.length;i0) {pos=0; callback(string);}; else {pos=string.length; occurrence = Math.abs(occurrence); callbackNegative(string);} 1152 | // MsgBox(_occurrence, occurrence); 1153 | if (_occurrence==occurrence) return pos; else return 0; 1154 | } 1155 | 1156 | //MsgBox(StringInStr("d_dsadhell_helld-hell", "hell", 0, -3)); 1157 | //MsgBox(StringInStr("d_dsadhell_helld-hell", "hell", 0, -2)); 1158 | //MsgBox(StringInStr("d_dsadhell_helld-hell", "hell", 0, 2)); 1159 | //MsgBox(StringInStr("d_dsadhell_helld-hell", "hell", 0, 1)); 1160 | //Exit(); 1161 | 1162 | //StringIsAlNum Checks if a string contains only alphanumeric characters. 1163 | function StringIsAlNum(s) 1164 | { 1165 | return /^[0-9a-z]+$/i.test(s)?1:0; 1166 | } 1167 | 1168 | //StringIsAlpha Checks if a string contains only alphabetic characters. 1169 | function StringIsAlpha(s) 1170 | { 1171 | return /^[a-z]+$/gi.test(s)?1:0; 1172 | } 1173 | 1174 | //StringIsASCII Checks if a string contains only ASCII characters in the range 0x00 - 0x7f (0 - 127). 1175 | function StringIsAlpha(s) 1176 | { 1177 | return /^[\u0000-\u007f]+$/gi.test(s)?1:0; 1178 | } 1179 | 1180 | //StringIsDigit Checks if a string contains only digit (0-9) characters. 1181 | function StringIsDigit(s) 1182 | { 1183 | return /^\d+$/gi.test(s); 1184 | } 1185 | 1186 | //StringIsFloat Checks if a string is a floating point number. 1187 | function StringIsFloat(s) 1188 | { 1189 | if (typeof s == "string") return /^-?(\d+\.\d*|\d*\.\d+)$/gi.test(s)?1:0; 1190 | if (typeof s == "number") return s!=Math.round(s)?1:0 ; 1191 | } 1192 | 1193 | /* 1194 | MsgBox(StringIsFloat("1.5")); //returns 1 1195 | MsgBox(StringIsFloat("7.")); //returns 1 since contains decimal 1196 | MsgBox(StringIsFloat("-.0")); //returns 1 1197 | MsgBox(StringIsFloat("3/4")); //returns 0 since '3' slash '4' is not a float 1198 | MsgBox(StringIsFloat("2")); //returns 0 since '2' is an interger, not a float 1199 | 1200 | MsgBox(StringIsFloat(1.5)); //returns 1 since 1.5 converted to string contain . 1201 | MsgBox(StringIsFloat(1.0)); //returns 0 since 1.0 converted to string does not contain . 1202 | Exit(); 1203 | */ 1204 | 1205 | //StringUpper Converts a string to uppercase. Asc Returns the ASCII code of a character. 1206 | function StringUpper(s) 1207 | { 1208 | return s.toUpperCase(); 1209 | } 1210 | 1211 | //StringIsLower Checks if a string contains only lowercase characters. 1212 | function StringIsLower(s) 1213 | { 1214 | return s.toLowerCase()==s?1:0; 1215 | } 1216 | 1217 | //StringIsUpper Checks if a string contains only uppercase characters. 1218 | function StringIsUpper(s) 1219 | { 1220 | return s.toUpperCase()==s?1:0; 1221 | } 1222 | 1223 | //StringLower Converts a string to lowercase. 1224 | function StringLower(s) 1225 | { 1226 | return s.toLowerCase(); 1227 | } 1228 | 1229 | //StringTrimLeft Trims a number of characters from the left hand side of a string. 1230 | function StringTrimLeft(s, count) 1231 | { 1232 | if (count>=s.length) return 0; 1233 | return s.slice(count); 1234 | } 1235 | //MsgBox(StringTrimLeft("I am a string", 3)); 1236 | //Exit(); 1237 | 1238 | //StringTrimRight Trims a number of characters from the right hand side of a string. 1239 | function StringTrimRight(s, count) 1240 | { 1241 | if (count>=s.length) return 0; 1242 | return s.slice(0, -count); 1243 | } 1244 | //MsgBox(StringTrimRight("I am a string", 3)); 1245 | //Exit(); 1246 | 1247 | //StringIsInt Checks if a string is an integer. 1248 | function StringIsInt(s) 1249 | { 1250 | if (typeof s == "string") return /^-?\d+$/gi.test(s)?1:0; 1251 | if (typeof s == "number") return s==Math.round(s)?1:0 ; 1252 | return 0; 1253 | } 1254 | 1255 | //StringIsSpace Checks if a string contains only whitespace characters. 1256 | function StringIsSpace(s) 1257 | { 1258 | return /^\s+$/.test(s)?1:0; 1259 | } 1260 | 1261 | //StringStripWS Strips the white space in a string. 1262 | function StringStripWS(s, flag) 1263 | { 1264 | if ((flag & 1) == 1) s = s.replace(/^\s+/,""); 1265 | if ((flag & 2) == 2) s = s.replace(/\s+$/,""); 1266 | if ((flag & 4) == 4) s = s.replace(/\s+/g," "); 1267 | if ((flag & 8) == 8) s = s.replace(/\s+/g,""); 1268 | 1269 | return s; 1270 | } 1271 | //MsgBox('"'+ StringStripWS(" this is a line of text ", 3)+'"'); 1272 | //Exit(); 1273 | 1274 | //StringIsXDigit Checks if a string contains only hexadecimal digit (0-9, A-F) characters. 1275 | function StringIsXDigit(s) 1276 | { 1277 | if (typeof s == "string") return /^\w+$/.test(s)?1:0; 1278 | if (typeof s == "number") return s==Math.round(s)?1:0; 1279 | 1280 | } 1281 | //MsgBox(StringIsXDigit("00FC")); 1282 | //Exit(); 1283 | 1284 | //StringLen Returns the number of characters in a string. 1285 | function StringLen(s) 1286 | { 1287 | return s.length; 1288 | } 1289 | 1290 | //StringRight Returns a number of characters from the right-hand side of a string. 1291 | function StringRight(s, count) 1292 | { 1293 | if (count>=s.length) return ""; 1294 | return s.slice(-count); 1295 | } 1296 | //MsgBox(StringRight("00FC", 2)); 1297 | //Exit(); 1298 | 1299 | //StringLeft Returns a number of characters from the left-hand side of a string. 1300 | function StringLeft(s, count) 1301 | { 1302 | if (count>=s.length) return ""; 1303 | return s.slice(0, count); 1304 | } 1305 | //MsgBox(StringLeft("00FC", 2)); 1306 | //Exit(); 1307 | 1308 | //StringStripCR Removes all carriage return values ( Chr(13) ) from a string. 1309 | function StringStripCR(s) 1310 | { 1311 | return s.replace(/\r/g,""); 1312 | } 1313 | 1314 | //StringAddCR Takes a string and prefixes all linefeed characters ( Chr(10) ) with a carriage return character ( Chr(13) ). 1315 | function StringAddCR(s) 1316 | { 1317 | return s.replace(/\r?\n/g,"\r\n"); 1318 | } 1319 | 1320 | //StringMid Extracts a number of characters from a string. 1321 | function StringMid(s, start, count) 1322 | { 1323 | return s.slice(start, start+count); 1324 | } 1325 | //MsgBox(StringMid("I am a string", 3, 3)); 1326 | //Exit(); 1327 | 1328 | //StringSplit Splits up a string into substrings depending on the given delimiters. 1329 | function StringSplit(s, d) 1330 | { 1331 | return s.split(d); 1332 | } 1333 | 1334 | //StringReplace Replaces substrings in a string. 1335 | function StringReplace (string, searchstring, replacestring, occurrence, casesense) 1336 | { 1337 | casesense = casesense || 0; 1338 | occurrence = occurrence || 0; 1339 | var s="", i=0; 1340 | var r=new RegExp(searchstring.replace(/[\^\$\+\(\)\*\{\}\[\]\|\.]/g,"\\$&") ,(!casesense?"i":"")+"g"); 1341 | var matches = string.match(r); 1342 | if (!matches) return string; 1343 | 1344 | string = string.replace(r, ":DELETE_TEMP_098989:$&:DELETE_TEMP_098989:"); 1345 | //MsgBox(string); 1346 | var parts = string.split(new RegExp(matches.join("|"), (!casesense?"i":"")+"g")); 1347 | var result=[]; 1348 | 1349 | if (occurrence==0) return parts.join(replacestring).replace(/:DELETE_TEMP_098989:/g, ""); 1350 | if (occurrence>0) 1351 | { 1352 | for (var j=0, l=parts.length;j0;j--) 1365 | { 1366 | result[j*2]=parts[j]; 1367 | if ((parts.length-1-j)= len) ? '' : Array(1 + len - str.length >>> 0).join(chr); 1389 | return leftJustify ? str + padding : padding + str; 1390 | }; 1391 | 1392 | // justify() 1393 | var justify = function(value, prefix, leftJustify, minWidth, zeroPad) { 1394 | var diff = minWidth - value.length; 1395 | if (diff > 0) { 1396 | if (leftJustify || !zeroPad) { 1397 | value = pad(value, minWidth, ' ', leftJustify); 1398 | } else { 1399 | value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length); 1400 | } 1401 | } 1402 | return value; 1403 | }; 1404 | 1405 | // formatBaseX() 1406 | var formatBaseX = function(value, base, prefix, leftJustify, minWidth, precision, zeroPad) { 1407 | // Note: casts negative numbers to positive ones 1408 | var number = value >>> 0; 1409 | prefix = prefix && number && {'2': '0b', '8': '0', '16': '0x'}[base] || ''; 1410 | value = prefix + pad(number.toString(base), precision || 0, '0', false); 1411 | return justify(value, prefix, leftJustify, minWidth, zeroPad); 1412 | }; 1413 | 1414 | // formatString() 1415 | var formatString = function(value, leftJustify, minWidth, precision, zeroPad) { 1416 | if (precision != null) { 1417 | value = value.slice(0, precision); 1418 | } 1419 | return justify(value, '', leftJustify, minWidth, zeroPad); 1420 | }; 1421 | 1422 | // finalFormat() 1423 | var doFormat = function(substring, valueIndex, flags, minWidth, _, precision, type) { 1424 | if (substring == '%%') return '%'; 1425 | 1426 | // parse flags 1427 | var leftJustify = false, positivePrefix = '', zeroPad = false, prefixBaseX = false; 1428 | for (var j = 0; flags && j < flags.length; j++) switch (flags.charAt(j)) { 1429 | case ' ': positivePrefix = ' '; break; 1430 | case '+': positivePrefix = '+'; break; 1431 | case '-': leftJustify = true; break; 1432 | case '0': zeroPad = true; break; 1433 | case '#': prefixBaseX = true; break; 1434 | } 1435 | 1436 | // parameters may be null, undefined, empty-string or real valued 1437 | // we want to ignore null, undefined and empty-string values 1438 | if (!minWidth) { 1439 | minWidth = 0; 1440 | } else if (minWidth == '*') { 1441 | minWidth = +a[i++]; 1442 | } else if (minWidth.charAt(0) == '*') { 1443 | minWidth = +a[minWidth.slice(1, -1)]; 1444 | } else { 1445 | minWidth = +minWidth; 1446 | } 1447 | 1448 | // Note: undocumented perl feature: 1449 | if (minWidth < 0) { 1450 | minWidth = -minWidth; 1451 | leftJustify = true; 1452 | } 1453 | 1454 | if (!isFinite(minWidth)) { 1455 | throw new Error('sprintf: (minimum-)width must be finite'); 1456 | } 1457 | 1458 | if (!precision) { 1459 | precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type == 'd') ? 0 : void(0); 1460 | } else if (precision == '*') { 1461 | precision = +a[i++]; 1462 | } else if (precision.charAt(0) == '*') { 1463 | precision = +a[precision.slice(1, -1)]; 1464 | } else { 1465 | precision = +precision; 1466 | } 1467 | 1468 | // grab value using valueIndex if required? 1469 | var value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++]; 1470 | 1471 | switch (type) { 1472 | case 's': return formatString(String(value), leftJustify, minWidth, precision, zeroPad); 1473 | case 'c': return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad); 1474 | case 'b': return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad); 1475 | case 'o': return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad); 1476 | case 'x': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad); 1477 | case 'X': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad).toUpperCase(); 1478 | case 'u': return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad); 1479 | case 'i': 1480 | case 'd': { 1481 | var number = parseInt(+value); 1482 | var prefix = number < 0 ? '-' : positivePrefix; 1483 | value = prefix + pad(String(Math.abs(number)), precision, '0', false); 1484 | return justify(value, prefix, leftJustify, minWidth, zeroPad); 1485 | } 1486 | case 'e': 1487 | case 'E': 1488 | case 'f': 1489 | case 'F': 1490 | case 'g': 1491 | case 'G': 1492 | { 1493 | var number = +value; 1494 | var prefix = number < 0 ? '-' : positivePrefix; 1495 | var method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())]; 1496 | var textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2]; 1497 | value = prefix + Math.abs(number)[method](precision); 1498 | return justify(value, prefix, leftJustify, minWidth, zeroPad)[textTransform](); 1499 | } 1500 | default: return substring; 1501 | } 1502 | }; 1503 | 1504 | return format.replace(regex, doFormat); 1505 | } 1506 | 1507 | function printf( ) { // Output a formatted string 1508 | // 1509 | // + original by: Ash Searle (http://hexmen.com/blog/) 1510 | // + improved by: Michael White (http://crestidg.com) 1511 | 1512 | var ret = sprintf.apply(this, arguments); 1513 | return ret; 1514 | } 1515 | 1516 | /* 1517 | $n = 43951789; 1518 | $u = -43951789; 1519 | 1520 | //; notice the double %%, this prints a literal '%' character 1521 | printf("%%d = '%d'\n", $n); //'43951789' standard integer representation 1522 | printf("%%e = '%e'\n", $n); //'4.395179e+007' scientific notation 1523 | printf("%%u = '%u'\n", $n); //'43951789' unsigned integer representation of a positive integer 1524 | printf("%%u <0 = '%u'\n", $u); //'4251015507' unsigned integer representation of a negative integer 1525 | printf("%%f = '%f'\n", $n); //'43951789.000000' floating point representation 1526 | printf("%%.2f = '%.2f'\n", $n); //'43951789.00' floating point representation 2 digits after the decimal point 1527 | printf("%%o = '%o'\n", $n); //'247523255' octal representation 1528 | printf("%%s = '%s'\n", $n); //'43951789' string representation 1529 | printf("%%x = '%x'\n", $n); //'29ea6ad' hexadecimal representation (lower-case) 1530 | printf("%%X = '%X'\n", $n); //'29EA6AD' hexadecimal representation (upper-case) 1531 | 1532 | printf("%%+d = '%+d'\n", $n); //'+43951789' sign specifier on a positive integer 1533 | printf("%%+d <0= '%+d'\n", $u); //'-43951789' sign specifier on a negative integer 1534 | 1535 | 1536 | $s = 'monkey'; 1537 | $t = 'many monkeys'; 1538 | 1539 | printf("%%s = [%s]\n", $s); //[monkey] standard string output 1540 | printf("%%10s = [%10s]\n", $s); //[ monkey] right-justification with spaces 1541 | printf("%%-10s = [%-10s]\n", $s); //[monkey ] left-justification with spaces 1542 | printf("%%010s = [%010s]\n", $s); //[0000monkey] zero-padding works on strings too 1543 | printf("%%10.10s = [%10.10s]\n", $t); // [many monke] left-justification but with a cutoff of 10 characters 1544 | 1545 | printf("%04d-%02d-%02d\n", 2008, 4, 1); 1546 | Exit(); 1547 | //*/ 1548 | 1549 | //StringFormat Returns a formatted string (similar to the C sprintf() function). 1550 | function StringFormat() 1551 | { 1552 | return sprintf.apply(this, arguments); 1553 | } 1554 | 1555 | //StringToASCIIArray Converts a string to an array containing the ASCII code of each character. 1556 | function StringToASCIIArray(string, start, end) 1557 | { 1558 | start = start || 0; 1559 | end = end || string.length; 1560 | string = string.slice(start, end); 1561 | return string.split("").map(function a(s){return s.charCodeAt(0);}) 1562 | } 1563 | 1564 | //MsgBox(StringToASCIIArray("abc1")); 1565 | //Exit(); 1566 | 1567 | //StringFromASCIIArray Converts an array of ASCII codes to a string. 1568 | function StringFromASCIIArray(ar, start, end) 1569 | { 1570 | start = start || 0; 1571 | end = end || ar.length; 1572 | ar = ar.slice(start, end); 1573 | return String.fromCharCode.apply(this, ar); 1574 | } 1575 | 1576 | /* 1577 | var s; 1578 | MsgBox(s=StringToASCIIArray("abc1")); 1579 | MsgBox(StringFromASCIIArray(s)); 1580 | Exit(); 1581 | */ 1582 | 1583 | //ProcessList Returns an array listing the currently running processes (names and PIDs). 1584 | function ProcessList(name) 1585 | { 1586 | var Proc, query; 1587 | 1588 | query = name?("SELECT * FROM Win32_Process WHERE Name='"+name+"'"):"SELECT * FROM Win32_Process"; 1589 | Proc = WMIQuery("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2", query); 1590 | if (Proc.length>0) return Proc.map(function (p){return [p.Name, p.ProcessId];}); 1591 | return []; 1592 | } 1593 | 1594 | //MsgBox(ProcessList().join("\r\n")); 1595 | //MsgBox(ProcessList("svchost.exe").join("\r\n")); 1596 | 1597 | //Sleep Pause script execution. 1598 | function Sleep(ms) 1599 | { 1600 | if (this.WScript) return WScript.Sleep(ms); 1601 | 1602 | var serv = GetObject("winmgmts:\\\\.\\root\\cimv2"); 1603 | var o = serv.Get("__IntervalTimerInstruction").SpawnInstance_(); 1604 | o.TimerId = "Sleep"; 1605 | o.IntervalBetweenEvents = ms; 1606 | o.Put_(); 1607 | 1608 | serv.ExecNotificationQuery("SELECT * FROM __TimerEvent WHERE TimerId='Sleep'").NextEvent(); 1609 | } 1610 | /* 1611 | Sleep(3000); 1612 | MsgBox(0); 1613 | Exit(); 1614 | //*/ 1615 | 1616 | //AscW Returns the unicode code of a character. 1617 | function AscW(s) 1618 | { 1619 | return s.charCodeAt(0); 1620 | } 1621 | 1622 | //Asc Returns the ASCII code of a character. 1623 | function Asc(str) 1624 | { 1625 | var c = str.charCodeAt(0); 1626 | if (c<128) return c; 1627 | 1628 | /* 1629 | var CP1251=["Ђ","Ѓ","‚","ѓ","„","…","†","‡","€","‰","Љ","‹","Њ","Ќ","Ћ","Џ","ђ","‘","’","“","”","•","–","—","˜","™","љ","›","њ","ќ","ћ","џ"," ","Ў","ў","Ј","¤","Ґ","¦","§","Ё","©","Є","«","¬","­","®","Ї","°","±","І","і","ґ","µ","¶","·","ё","№","є","»","ј","Ѕ","ѕ","ї","А","Б","В","Г","Д","Е","Ж","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ч","Ш","Щ","Ъ","Ы","Ь","Э","Ю","Я","а","б","в","г","д","е","ж","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ч","ш","щ","ъ","ы","ь","э","ю","я"]; 1630 | var res = CP1251.indexOf(str.charAt(0)); 1631 | if (res<0) return 0; 1632 | return 128+res; 1633 | */ 1634 | 1635 | var vbe = new ActiveXObject('ScriptControl'); 1636 | vbe.Language = 'VBScript'; 1637 | vbe.AddCode("dim buffer"); 1638 | vbe.CodeObject.buffer = str.charAt(0); 1639 | return vbe.eval("Asc(buffer)"); 1640 | } 1641 | /* 1642 | MsgBox(Asc("абв")); 1643 | MsgBox(Asc("‰")); 1644 | MsgBox(Asc("™")); 1645 | Exit(); 1646 | //*/ 1647 | 1648 | //ChrW Returns a character corresponding to a unicode code. 1649 | function ChrW(n) 1650 | { 1651 | return String.fromCharCode(n); 1652 | } 1653 | //MsgBox(ChrW(65)); 1654 | 1655 | 1656 | //Chr Returns a character corresponding to an ASCII code. 1657 | function Chr(num) 1658 | { 1659 | num%=255; 1660 | if (num<128) return String.fromCharCode(num); 1661 | var vbe = new ActiveXObject('ScriptControl'); 1662 | vbe.Language = 'VBScript'; 1663 | vbe.AddCode("dim buffer"); 1664 | vbe.CodeObject.buffer = num; 1665 | var res = vbe.eval("Chr(buffer)"); 1666 | vbe = null; 1667 | return res; 1668 | } 1669 | //MsgBox(Chr(190)); 1670 | 1671 | //TimerInit Returns a handle that can be passed to TimerDiff() to calculate the difference in milliseconds. 1672 | function TimerInit() 1673 | { 1674 | return new Date().valueOf(); 1675 | } 1676 | //MsgBox(TimerInit()); 1677 | 1678 | //TimerDiff Returns the difference in time from a previous call to TimerInit(). 1679 | function TimerDiff(t) 1680 | { 1681 | var d = new Date().valueOf(); 1682 | t = t || d; 1683 | return d-t; 1684 | } 1685 | /* 1686 | var q=TimerInit(); 1687 | Sleep(5000); 1688 | MsgBox(TimerDiff(q)); 1689 | //*/ 1690 | 1691 | //Hex Returns a string representation of an integer or of a binary type converted to hexadecimal. 1692 | function Hex(expression, length) 1693 | { 1694 | var res = expression.toString(16); 1695 | length = length || res.length; 1696 | return new Array(length+2).join("0").replace(new RegExp(".{"+length+"}$"), res); 1697 | } 1698 | //MsgBox(Hex(1033, 4)); 1699 | 1700 | //Dec Returns a numeric representation of a hexadecimal string. 1701 | function Dec(v) 1702 | { 1703 | return parseInt(v, 16); 1704 | } 1705 | 1706 | //ProcessGetStats Returns an array about Memory or IO infos of a running process. 1707 | function ProcessGetStats(ProcName, type) 1708 | { 1709 | type = (type==1)?1:0; 1710 | var processObject; 1711 | if (!ProcName) ProcName = GetPID(); 1712 | if (typeof ProcName == "number") 1713 | { 1714 | try { 1715 | var Proc = WMIQuery("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2", "SELECT * FROM Win32_Process WHERE ProcessId='"+ProcName+"'"); 1716 | if (Proc.length>0) processObject=Proc[0]; 1717 | 1718 | } catch(e) { 1719 | return 0; 1720 | } 1721 | } 1722 | 1723 | try { 1724 | var Proc = WMIQuery("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2", "SELECT * FROM Win32_Process WHERE Name='"+ProcName+"'"); 1725 | if (Proc.length>0) processObject=Proc[0]; 1726 | 1727 | } catch(e) { 1728 | return 0; 1729 | } 1730 | 1731 | if (type==0) return [processObject.WorkingSetSize, processObject.PeakWorkingSetSize]; 1732 | return [processObject.ReadOperationCount,processObject.WriteOperationCount,processObject.OtherOperationCount, processObject.ReadTransferCount, processObject.WriteTransferCount, processObject.OtherTransferCount]; 1733 | 1734 | } 1735 | /* 1736 | WshShell.Run("notepad"); 1737 | MsgBox(ProcessGetStats()); 1738 | MsgBox(ProcessGetStats("notepad.exe",0)); 1739 | MsgBox(ProcessGetStats("notepad.exe", 1)); 1740 | ProcessClose("notepad.exe"); 1741 | //*/ 1742 | 1743 | 1744 | //ProcessSetPriority Changes the priority of a process 1745 | function ProcessSetPriority(ProcName, priority ) 1746 | { 1747 | if (ProcName==null) return 0; 1748 | if (priority==null) return 0; 1749 | 1750 | var processObject; 1751 | if (!ProcName) ProcName = GetPID(); 1752 | if (typeof ProcName == "number") 1753 | { 1754 | try { 1755 | var Proc = WMIQuery("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2", "SELECT * FROM Win32_Process WHERE ProcessId='"+ProcName+"'"); 1756 | if (Proc.length>0) processObject=Proc[0]; 1757 | 1758 | } catch(e) { 1759 | return 0; 1760 | } 1761 | } 1762 | 1763 | try { 1764 | var Proc = WMIQuery("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2", "SELECT * FROM Win32_Process WHERE Name='"+ProcName+"'"); 1765 | if (Proc.length>0) processObject=Proc[0]; 1766 | 1767 | } catch(e) { 1768 | return 0; 1769 | } 1770 | /* 1771 | 0 - Idle/Low 1772 | 1 - Below Normal 1773 | 2 - Normal 1774 | 3 - Above Normal 1775 | 4 - High 1776 | 5 - Realtime (Use with caution, may make the system unstable) 1777 | */ 1778 | var d=[128, 64, 32, 32768, 256]; 1779 | try { 1780 | processObject.SetPriority(d[priority%5]); 1781 | return 1; 1782 | } catch(e) { 1783 | return 0; 1784 | } 1785 | } 1786 | /* 1787 | WshShell.Run("notepad.exe"); 1788 | Sleep(2000) 1789 | MsgBox(ProcessSetPriority("notepad.exe", 0)); 1790 | ProcessClose("notepad.exe"); 1791 | //*/ 1792 | 1793 | 1794 | //FileGetTime Returns the time and date information for a file. 1795 | function FileGetTime(filename, option, format) 1796 | { 1797 | option = option || 0; 1798 | format = format || 0; 1799 | 1800 | try { 1801 | var f = FSO.GetFile(filename); 1802 | var res = ""; 1803 | if (option==0) res = f.DateLastModified; 1804 | if (option==1) res = f.DateCreated; 1805 | if (option==2) res = f.DateLastAccessed; 1806 | 1807 | res = (new Date(res)); 1808 | res = [res.getFullYear(), res.getMonth()+1, res.getDate(), res.getHours(), res.getMinutes(), res.getSeconds()]; 1809 | if (format==0) return res; 1810 | return res.map(function (i){if ((i+"").length<3) return ("00"+i).slice(-2); else return i;}).join(""); 1811 | } catch(e) { 1812 | return 0; 1813 | } 1814 | //*/ 1815 | } 1816 | //MsgBox(FileGetTime(GetScriptFullPath(), 1, 1)); 1817 | //Exit(); 1818 | 1819 | //IsAdmin Checks if the current user has full administrator privileges. 1820 | function IsAdmin() 1821 | { 1822 | var path = fso.GetSpecialFolder(1) + "\\IsAdmin.txt"; 1823 | try { 1824 | f = fso.CreateTextFile(path,true); 1825 | f.WriteLine("test"); 1826 | f.Close(); 1827 | fso.DeleteFile(path); 1828 | return true; 1829 | } catch(e) { 1830 | return false; 1831 | } 1832 | } 1833 | //MsgBox(IsAdmin()); 1834 | //Exit(); 1835 | 1836 | //ClipGet Retrieves text from the clipboard. 1837 | function ClipGet() 1838 | { 1839 | return new ActiveXObject("HTMLFile").parentWindow.clipboardData.getData("text"); 1840 | } 1841 | 1842 | //ClipPut Writes text to the clipboard. 1843 | function ClipPut(data) 1844 | { 1845 | try { 1846 | data = data.replace(/[\\'"]/g,"\\$&"); 1847 | new ActiveXObject("WScript.Shell").Run('mshta.exe "javascript:window.clipboardData.setData(\'text\',\''+data+'\');close()"',0); 1848 | return true; 1849 | } catch(e) { 1850 | return false; 1851 | } 1852 | } 1853 | /* 1854 | MsgBox(ClipGet()); 1855 | MsgBox(ClipPut('"tutu4\\"')); 1856 | MsgBox(ClipGet()); 1857 | Exit(); 1858 | //*/ 1859 | 1860 | //FileSelectFolder Initiates a Browse For Folder dialog. 1861 | function FileSelectFolder (dialogText, rootDir, flag, initialDir, hwnd) 1862 | { 1863 | //initialDir - ignore 1864 | 1865 | dialogText = dialogText || ""; 1866 | rootDir = rootDir || 0; 1867 | hwnd = hwnd || 0; 1868 | initialDir = initialDir || 0; 1869 | 1870 | var objShell = new ActiveXObject("shell.application"); 1871 | var objFolder; 1872 | flag = flag || 1; 1873 | flag = flag==1?0x200:flag; 1874 | flag = flag==2?0x40:flag; 1875 | flag = flag==4?0x10:flag; 1876 | 1877 | objFolder = objShell.BrowseForFolder(hwnd, dialogText, flag, rootDir); 1878 | 1879 | if (objFolder != null) 1880 | { 1881 | return objFolder.Self.Path; 1882 | } 1883 | 1884 | return ""; 1885 | } 1886 | /* 1887 | FileSelectFolder("test","",1); 1888 | FileSelectFolder("test","",2); 1889 | FileSelectFolder("test","",4); 1890 | //*/ 1891 | 1892 | //Run Runs an external program. 1893 | function Run(app, workingdir, show_flag) 1894 | { 1895 | /* 1896 | SW_SHOWNORMAL 1 Файл будет запущен в обычном режиме. 1897 | SW_MAXIMIZE 3 Файл будет запущен развернутым на весь экран. 1898 | SW_MINIMIZE 6 Файл будет запущен свернутым. 1899 | SW_HIDE 0 Файл будет запущен скрытым. 1900 | */ 1901 | /*WMI 1902 | 1 - Window is shown minimized 1903 | 3 - Window is shown maximized 1904 | 5 - Window is shown in normal view 1905 | 12 - Window is hidden and not displayed to the user 1906 | */ 1907 | show_flag = show_flag || 0; 1908 | if (workingdir==="" || workingdir===0) workingdir=null; 1909 | 1910 | 1911 | switch(show_flag) 1912 | { 1913 | case 0: 1914 | show_flag = 12; 1915 | break; 1916 | case 3: 1917 | break; 1918 | case 6: 1919 | show_flag = 1; 1920 | break; 1921 | case 1: 1922 | show_flag = 5; 1923 | break; 1924 | default: 1925 | show_flag = 12; 1926 | } 1927 | 1928 | var objProcess = GetObject("winmgmts:\\\\.\\root\\cimv2:Win32_Process"); 1929 | var objInParams = objProcess.Methods_("Create").InParameters.SpawnInstance_(); 1930 | objInParams.CommandLine = app; 1931 | objInParams.CurrentDirectory = workingdir; 1932 | var objService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2") 1933 | var objStartup = objService.Get("Win32_ProcessStartup") 1934 | var objConfig = objStartup.SpawnInstance_(); 1935 | objConfig.ShowWindow = show_flag; 1936 | objInParams.ProcessStartupInformation = objConfig; 1937 | var objOutParams = objProcess.ExecMethod_("Create", objInParams); 1938 | return objOutParams.ProcessId || 0; 1939 | } 1940 | /* 1941 | var pid = Run('notepad',"", 1); 1942 | MsgBox(pid); 1943 | ProcessClose(pid); 1944 | Exit(); 1945 | //*/ 1946 | 1947 | //RunWait Runs an external program and pauses script execution until the program finishes. 1948 | function RunWait(app, workingdir, show_flag, timeout) 1949 | { 1950 | var process = Run(app, workingdir, show_flag); 1951 | ProcessWait(process, timeout); 1952 | return process; 1953 | } 1954 | /* 1955 | var pid = RunWait('notepad',"", 0, 5); 1956 | MsgBox(pid); 1957 | Exit(); 1958 | //*/ 1959 | 1960 | //FileGetShortName Returns the 8.3 short path+name of the path+name passed. 1961 | function FileGetShortName(path) 1962 | { 1963 | try { 1964 | if (FSO.FolderExists(path)) return FSO.GetFolder(path).ShortPath; 1965 | if (FSO.FileExists(path)) return FSO.GetFile(path).ShortPath; 1966 | return ""; 1967 | } catch(e) {return "";} 1968 | } 1969 | 1970 | //MsgBox(FileGetShortName("C:\\Documents and Settings\\Сохранялка почты")); 1971 | //Exit(); 1972 | 1973 | //FileGetLongName Returns the long path+name of the path+name passed. 1974 | function FileGetLongName(p) 1975 | { 1976 | var link = WshShell.CreateShortcut("%TMP%\\dummy.lnk"); 1977 | link.TargetPath = p; 1978 | var Result = link.TargetPath; 1979 | FileDelete("%TMP%\\dummy.lnk"); 1980 | return Result; 1981 | } 1982 | //MsgBox(FileGetLongName(GetHomeDrive() + "\\PROGRA~1")); 1983 | //Exit(); 1984 | 1985 | //FileGetSize Returns the size of a file in bytes. 1986 | function FileGetSize(path) 1987 | { 1988 | try { 1989 | return FSO.GetFile(path).Size; 1990 | } catch(e) { 1991 | return 0; 1992 | } 1993 | } 1994 | //MsgBox(FileGetSize(GetScriptFullPath())); 1995 | //Exit(); 1996 | 1997 | //DirGetSize Returns the size in bytes of a given directory. 1998 | function DirGetSize(path) 1999 | { 2000 | try { 2001 | return FSO.GetFolder(path).Size; 2002 | } catch(e) { 2003 | return 0; 2004 | } 2005 | } 2006 | //MsgBox(DirGetSize(GetWindowsDir())); 2007 | //Exit(); 2008 | 2009 | //EnvGet Retrieves an environment variable. 2010 | function EnvGet(str) 2011 | { 2012 | return WshShell.ExpandEnvironmentStrings(str); 2013 | } 2014 | 2015 | //FileCreateShortcut Creates a shortcut (.lnk) to a file. 2016 | function FileCreateShortcut (file, lnk, workdir, args, desc, icon, hotkey /*Example: CTRL + ALT + S*/, icon_number, state) 2017 | { 2018 | if (!file || !lnk) return 0; 2019 | if (icon_number===null) icon_number = ""; else icon_number =", "+icon_number; 2020 | 2021 | file = WshShell.ExpandEnvironmentStrings(file); 2022 | lnk = WshShell.ExpandEnvironmentStrings(lnk); 2023 | 2024 | try { 2025 | var WshShortcut = WshShell.CreateShortcut(lnk); 2026 | WshShortcut.Arguments = args ||""; 2027 | WshShortcut.Description = desc || ""; 2028 | WshShortcut.HotKey = hotkey || ""; 2029 | WshShortcut.IconLocation = icon!=""?(icon+icon_number): ""; 2030 | WshShortcut.TargetPath = file; 2031 | WshShortcut.WindowStyle = state; 2032 | WshShortcut.WorkingDirectory = workdir || ""; 2033 | WshShortcut.Save(); 2034 | return 1; 2035 | } catch(e) {return 0;} 2036 | } 2037 | 2038 | //MsgBox(FileCreateShortcut(GetWindowsDir() + "\\explorer.exe", GetDesktopDir() + "\\Shortcut Example.lnk", GetWindowsDir(), "/e,c:\\", "Tooltip description of the shortcut.", GetSystemDir() + "\\shell32.dll", "CTRL+ALT+t", "15", 7)); 2039 | //Exit(); 2040 | 2041 | 2042 | //FileGetShortcut Retrieves details about a shortcut. 2043 | //return (file, lnk, workdir, args, desc, icon, hotkey, icon_number, state) 2044 | function FileGetShortcut(lnk) 2045 | { 2046 | var result = []; 2047 | if (!FileExists(lnk)) return 0; 2048 | try { 2049 | var WshShortcut = WshShell.CreateShortcut(lnk); 2050 | result[0]=WshShortcut.TargetPath; 2051 | result[1]=lnk; 2052 | result[2]=WshShortcut.WorkingDirectory; 2053 | result[3]=WshShortcut.Arguments; 2054 | result[4]=WshShortcut.Description; 2055 | result[5]=(WshShortcut.IconLocation+"").replace(/,\s*\d+\s*$/,""); 2056 | result[6]=WshShortcut.HotKey; 2057 | var tmp = (WshShortcut.IconLocation+"").match(/,\s*\d+\s*$/); 2058 | if (tmp) tmp = tmp.toString().replace(/[^\d]/g,""); else tmp = ""; 2059 | result[7]=tmp; 2060 | result[8]=WshShortcut.WindowStyle; 2061 | 2062 | return result; 2063 | } catch(e) {return 0;} 2064 | } 2065 | /* 2066 | FileCreateShortcut(GetWindowsDir() + "\\explorer.exe", GetDesktopDir() + "\\cmd.exe.lnk", GetWindowsDir(), "/e,c:\\", "Tooltip description of the shortcut.", GetSystemDir() + "\\shell32.dll", "CTRL+ALT+t", "15", 7); 2067 | var res = FileGetShortcut(GetDesktopDir() + "\\cmd.exe.lnk"); 2068 | MsgBox(res); 2069 | res[0]=GetWindowsDir() + "\\System32\\calc.exe"; 2070 | FileCreateShortcut.apply(null, res); 2071 | res = FileGetShortcut(GetDesktopDir() + "\\cmd.exe.lnk"); 2072 | MsgBox(res); 2073 | Exit(); 2074 | //For test press CTRL+ALT+T 2075 | //*/ 2076 | 2077 | //FileSearch 2078 | function FileSearch(dir, pattern, callback) 2079 | { 2080 | if (dir==0 || dir=="" || dir==null) dir = WshShell.CurrentDirectory; 2081 | if (pattern==0 || pattern==null) pattern=/./; 2082 | if (typeof pattern=="string") pattern=new RegExp(pattern.replace(/[\.\^\$\%\{\}\[\]\\\+]/g,"\\$&").replace(/[\?\*]/g,".$&")+"$","i"); 2083 | if (!callback) return 0; 2084 | 2085 | var func = arguments.callee; 2086 | var level = 0; 2087 | var exit_flag = false; 2088 | 2089 | if (!func.ids) func.ids = {}; 2090 | var set_search_id = GenerateString(); 2091 | func.ids[set_search_id]=1; e 2092 | 2093 | var main_folder_path = WshShell.ExpandEnvironmentStrings(dir); 2094 | try { 2095 | var main_folder = fso.GetFolder(main_folder_path); 2096 | } catch (e) {delete func.ids[set_search_id]; return 0}; 2097 | 2098 | function DirWithSubFolders(_folder){ 2099 | if (exit_flag) return; 2100 | level++; 2101 | EnumerateFiles(_folder); 2102 | var more_folders = new Enumerator(_folder.SubFolders); 2103 | for (;!more_folders.atEnd();more_folders.moveNext()) 2104 | { 2105 | OneFolder = more_folders.item(); 2106 | try { 2107 | DirWithSubFolders (OneFolder); 2108 | } catch (e) {}; 2109 | } 2110 | level--; 2111 | } 2112 | 2113 | function EnumerateFiles(_folder){ 2114 | if (exit_flag) return; 2115 | var more_files = new Enumerator(_folder.Files); 2116 | for (;!more_files.atEnd();more_files.moveNext()) 2117 | { 2118 | one_file = more_files.item(); 2119 | if (pattern.test(one_file.Path)) callback(one_file.Path, level, set_search_id); 2120 | if (!func.ids[set_search_id]){ exit_flag=true; return 1;} 2121 | } 2122 | } 2123 | 2124 | DirWithSubFolders(main_folder); 2125 | delete arguments.callee.ids[set_search_id]; 2126 | 2127 | return 1; 2128 | } 2129 | 2130 | function FileSearchStop(search_id) 2131 | { 2132 | delete FileSearch.ids[search_id]; 2133 | } 2134 | 2135 | /* 2136 | var i=0, count=1, ar=[]; 2137 | FileSearch("%USERPROFILE%", "*.hta", function(f, l, id){i++; if (i<=count) ar.push(f); FileSearchStop(id)}); 2138 | MsgBox(ar); 2139 | Exit(); 2140 | //*/ 2141 | 2142 | function FileSearchAll(dir, pattern, level) 2143 | { 2144 | var ar=[]; 2145 | level = level || 0; 2146 | FileSearch(dir, pattern, function(f, l, search_id){if (level!=0 && l<=level || level==0) ar.push(f); else FileSearchStop(search_id);}); 2147 | return ar; 2148 | } 2149 | //* 2150 | //MsgBox(FileSearchAll("", "*.ht*").join("\r\n")); 2151 | //MsgBox(FileSearchAll("%USERPROFILE%", "*.hta").join("\r\n")); 2152 | //Exit(); 2153 | //*/ 2154 | 2155 | function FileFindFirst(v, count) 2156 | { 2157 | var i=0, count = count || 1, ar=[]; 2158 | FileSearch("", v, function(f, l, id){i++; if (i<=count) ar.push(f); FileSearchStop(id)}); 2159 | return ar[0]?ar[0]:""; 2160 | } 2161 | 2162 | //FileSetTime Sets the timestamp of one of more files. 2163 | function FileSetTime(root, mask, datestring, typeOfFunction, deep) 2164 | { 2165 | /*[FileSetTime[ 2166 | import System.Environment; 2167 | import System.IO; 2168 | 2169 | // searches files by a string type classic mask or regexp type mask. if in-param "callback" is undefined function returns an array of found pathes. 2170 | function Search(root, re, callback, deep) 2171 | { 2172 | var e, files=[], dirs=[], result=[]; 2173 | 2174 | if (!root) root = Directory.GetCurrentDirectory(); 2175 | 2176 | if (!re) re = /./; 2177 | 2178 | if (typeof re == "string" && /^\/.*\/[gmi ]*$/.test(re)) 2179 | { 2180 | var m = re.match(/(^\/.*\/)([gmi ]*)$/i); 2181 | re = new RegExp(m[1].replace(/^\/|\/$/g,""), m[2]); 2182 | } 2183 | 2184 | if (typeof re == "string") re = new RegExp("("+re.replace(/[\^\\\*\[\]\{\}\(\)\$]/g, "\\$&").replace(/\|/g,")|(").replace(/\?/g, ".").replace(/(\*)/g, ".*")+"$)", "gi"); 2185 | 2186 | if (!callback) callback = function (a){result.push(a)}; 2187 | 2188 | if (typeof deep=="undefined") deep = true; 2189 | deep = !!deep; 2190 | 2191 | try 2192 | { 2193 | files = Directory.GetFiles(root); 2194 | 2195 | for (var i=0, l=files.length; i