Wednesday 26 July 2017

Windows Update Cleanup missing from Disk Cleanup - Windows 2008R2

Background:
Your server is full, or at least one disk is. You've tried the usual things:
  • Sift through the *.tmp files
  • Clear out any history/downloWindows ads/cookies etc from your browser
  • Save & Clear the main logs (system, applicaiton etc) in Event Viewer

Finally you check the Windows Component Store (C:\Windows\WinSXS) and find it's huge. Thus, you'll need to clear it down but don't start trying to manually delete stuff since a lot of these files are used by the OS.

To clear up this folder in Win2012 onwards, you can just use Disk Cleanup and tick the Windows Update Cleanup box but for 2008R2 you'll need to install a patch to add in the Windows Update Cleanup Option.

Install KB2852386 - this gives extra functionality to the Disk Cleanup wizard which includes the ability to remove all old Windows Update files (i.e. a good portion of the WinSXS folder).

Problem:
In spite of having installed the patch, you open disk cleanup only to find Windows Update Cleanup is not appearing on the Disk Cleanup list. Sad times. 

Solution:
To get round this, open up an elevated CMD prompt and use the Cleanup Manager via this code:

Cleanmgr /sageset:1
 
(NB you can choose any number between 1 and 65355).
 
You'll now get a pop up which allows you to select all the things you want to clean for this iteration of CleanMgr. 
Click OK to save it.
 
Then in the cmd prompt enter:

Cleanmgr /sagerun:1

and your custom clean job will tick over.
 
You can even save the cleanup job to your desktop or stick it in a scheduled task with the following cmd line:

%systemroot%\system32\cmd.exe /c Cleanmgr /sagerun:XXXXX
 

Tuesday 11 July 2017

JQuery - Alter Value in Input Without Using Class or ID

In this example we have the following html code:

<!DOCTYPE html>
<html>

<body>
<h1>Please Give Us Money</h1>
<p>Donate Below</p>

<input name="donation" value="0.00" maxlength="6" size="3" type="text">
</body>
</html>


Because the input doesn't have a class or id, we have to locate our target by making use of some of the informaiton we do know. In this case, we will use the 'name' of the input. The following code will change the 'value' from 0.00 to 3.00 for any input on the page which has a 'name' of 'donation':

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
       $('input[name="donation"]').attr('value', '3.00');              
    });
</script>


If the input did have an id (or class, although id is more appropriate) this would be a lot simpler. The HTML line would look like this:

<input id='donate' name="donation" value="0.00" maxlength="6" size="3" type="text"> 

and the JQuery would look like this:

$('#donate').attr('value', '3.00');  

There are, no doubt, many other ways to achieve this but this is the way i found worked best for me.