Advertisement
Guest User

Untitled

a guest
Jul 11th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <package><job id="DrainNGenQueue.wsf">
  2. <script language="JScript">    
  3.     var wsh = WScript.CreateObject("WScript.Shell");
  4.     var fso = WScript.CreateObject("Scripting.FileSystemObject");
  5.     var is64bit = function () {
  6.         if (wsh.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%").indexOf("64") > 0)
  7.             return true;
  8.         return (wsh.ExpandEnvironmentStrings("%PROCESSOR_ARCHITEW6432%").indexOf("64") > 0);
  9.     }();
  10.     var isV4Installed = function () {
  11.         var v4NgenLoc = wsh.ExpandEnvironmentStrings("%windir%\\Microsoft.NET\\Framework\\v4.0.30319\\ngen.exe");
  12.         return fso.FileExists(v4NgenLoc);
  13.     }();
  14.     // Run an exe, collecting its exit code, stdout & stderr, optionally echoing the results to the window
  15.     var runToCompletion = function (exe, arguments, echo) {
  16.         var makeResult = function (exitCode, stdOut, stdErr) {
  17.             return { ExitCode: exitCode, StdOut: stdOut, StdErr: stdErr };
  18.         }
  19.         var getStream = function (strm) {
  20.             var line = "";
  21.             if (!strm.AtEndOfStream) {
  22.                 line = strm.ReadAll();
  23.                 if (echo)
  24.                     WScript.Echo(line);
  25.             }
  26.             return line;
  27.         }
  28.         var process = wsh.Exec(exe + " " + arguments);
  29.         var output = "";
  30.         var error = "";
  31.         while (process.Status == 0) {
  32.             WScript.Sleep(50);
  33.             output += getStream(process.StdOut);
  34.             error += getStream(process.StdErr);
  35.         }
  36.         output += getStream(process.StdOut);
  37.         error += getStream(process.StdErr);
  38.         return makeResult(process.ExitCode, output, error);
  39.     }
  40.     var ver = function () {
  41.         var ver = runToCompletion(wsh.ExpandEnvironmentStrings("%windir%\\system32\\cmd.exe"), "/C ver");
  42.         var rgx = / ([0-9]+)\.([0-9]+)\.[0-9]+/;
  43.         var res = rgx.exec(ver.StdOut);
  44.         return {major: res[1], minor :res[2]};
  45.     }();
  46.     // true if the OS version is 6.2 or later
  47.     var isOSWin8OrLater = (ver.major == 6 && ver.minor >= 2) || (ver.major > 6);
  48.     var preVista = (ver.major < 6);
  49.  
  50.     // This re-launches the script under an elevated cscript window if it's either
  51.    // not already running as elevated, or it's running under wscript.exe instead.
  52.    // Note that is doesn't pass any arguments, because this particular script doesn't have any
  53.    var validateElevatedCScript = function () {
  54.  
  55.         // Return "Elevated", "Not elevated", "Unknown", or "Error" regarding elevation status
  56.         var elevatedStatus = function () {
  57.             if (preVista)
  58.                 return "Unknown";
  59.             // From technet, translated from VBScript & munged
  60.             var whoami = runToCompletion("whoami", "/groups", false);
  61.             if (whoami.ExitCode == 0) {
  62.                 if (whoami.StdOut.indexOf("S-1-16-12288") >= 0) {
  63.                     return "Elevated";
  64.                 } else if (whoami.StdOut.indexOf("S-1-16-8192") >= 0) {
  65.                     return "Not elevated";
  66.                 } else {
  67.                     return "Unknown";
  68.                 }
  69.             } else if (whoami.StdErr.length != 0) {
  70.                 WScript.Echo(whoami.StdErr.ReadAll());
  71.             }
  72.             return "Error";
  73.         }();
  74.  
  75.         var shell = WScript.CreateObject("Shell.Application");
  76.         var scriptHost = WScript.FullName; // This is the path to cscript.exe or wscript.exe
  77.         var wsfPath = WScript.ScriptFullName; // This is the full path to the .wsf file being run
  78.         var isCScript = scriptHost.toLowerCase().indexOf("\\cscript.exe") >= 0;
  79.  
  80.         if (isCScript && elevatedStatus != "Not elevated")
  81.             return;
  82.         if (!isCScript)
  83.             scriptHost = fso.GetParentFolderName(scriptHost) + "\\cscript.exe";
  84.         if (preVista)
  85.             shell.ShellExecute(scriptHost, "\"" + wsfPath + "\"");
  86.         else
  87.             shell.ShellExecute(scriptHost, "\"" + wsfPath + "\"", "", "runas", 1);
  88.         WScript.Quit(0);
  89.     }();
  90.  
  91.     var drainNGenQueue = function (ver) {
  92.         var dotNetRoot = wsh.ExpandEnvironmentStrings("%windir%\\Microsoft.NET\\Framework");
  93.         var getNGenBinary = function (is64Bit, ver) {
  94.             return dotNetRoot + (is64Bit ? "64" : "") + "\\" + ver + "\\ngen.exe";
  95.         }
  96.         var ngen32 = getNGenBinary(false, ver);
  97.         var ngen64 = getNGenBinary(true, ver);
  98.         var argument = "executeQueuedItems";
  99.  
  100.         runToCompletion(ngen32, argument, true);
  101.         if (is64bit)
  102.             runToCompletion(ngen64, argument, true);
  103.     }
  104.     var drainAppStoreQueue = function () {
  105.         var schTasks = wsh.ExpandEnvironmentStrings("%windir%\\System32\\schtasks.exe");
  106.         var arguments = "/run /Tn \"\\Microsoft\\Windows\\.NET Framework\\.NET Framework NGEN v4.0.30319";
  107.        runToCompletion(schTasks, arguments + "\"", true);
  108.         if (is64bit)
  109.             runToCompletion(schTasks, arguments + " 64\"", true);
  110.    }
  111.  
  112.    drainNGenQueue(isV4Installed ? "v4.0.30319" : "v2.0.50727");
  113.    if (isOSWin8OrLater) {
  114.        drainAppStoreQueue();
  115.    }
  116. </script>
  117. </job></package>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement