A moan, a groan, my life story and how me, a technically minded person just can't seem to fit in with anybody.

Microsoft Exchange – Recover deleted items from Outlook

Have you ever emptied your deleted items folder in Microsoft Outlook and realised you really did need that email you just deleted?

Well your in luck as it can be recovered, providing that the Microsoft Exchange Server has been told to keep deleted emails for a certain period of time.

Firstly you need to make a registry edit on your local machine to make the option available to you in Outlook.

1) Close Outlook
2) Run Regedit
3) Navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Exchange\Client\Options
4) Add a new DWORD called DumpsterAlwaysOn
5) Set the DWORD to 1.
6) Close Regedit and launch Outlook.
7) Go to Tools->Recover Deleted Items…

There we have it. If you are not happy making changes to your registry yourself then you can use the following reg file that will make the change for you

Windows Registry Editor Version 5.00


Download Reg File Here

PHP – Get users SID from Active Directory via LDAP (objectsid)

Have you ever needed to read an AD users SID so you can use it as the unique identifier it is?

Well I did but when I read out objectsid from AD for a user I found a load of weird symbols. It turned out that the data outputted was binary data. So after some digging around to see how to translate the binary data to a human readable SID like S-1-5-21-823795046-756116320-56781596-16683 I got to work to write a PHP script that could do just that.

This is what I came up with:

[PHP]$suffix =””;
$base_dn = “dc=sub,dc=mydomain,dc=co,dc=uk”;
$server = “″;

$USERNAME = “username”;
$PASSWORD = “password”;

$USERNAMETOSEARCH = “user to get sid”;

$ds = ldap_connect($server);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
$r = ldap_bind($ds, $USERNAME.$suffix, $PASSWORD);
$sr = ldap_search($ds, $base_dn, “(samaccountname=”.$USERNAMETOSEARCH.”)”);
$entries = ldap_get_entries($ds, $sr);

// All SID’s begin with S-
$sid = “S-”;
// Convert Bin to Hex and split into byte chunks
$sidinhex = str_split(bin2hex($entries[0]['objectsid'][0]), 2);
// Byte 0 = Revision Level
$sid = $sid.hexdec($sidinhex[0]).”-”;
// Byte 1-7 = 48 Bit Authority
$sid = $sid.hexdec($sidinhex[6].$sidinhex[5].$sidinhex[4].$sidinhex[3].$sidinhex[2].$sidinhex[1]);
// Byte 8 count of sub authorities – Get number of sub-authorities
$subauths = hexdec($sidinhex[7]);
//Loop through Sub Authorities
for($i = 0; $i < $subauths; $i++) { $start = 8 + (4 * $i); // X amount of 32Bit (4 Byte) Sub Authorities $sid = $sid.”-”.hexdec($sidinhex[$start+3].$sidinhex[$start+2].$sidinhex[$start+1].$sidinhex[$start]); } echo $sid;[/PHP] Now this is written in PHP but I’m sure this code can be pretty much be translated to any other language.

PHP – Active Directory – Reading UserAccountControl

At the moment I’m doing a lot of work with Microsoft Active Directory and PHP. I’m building a few tools in PHP which reads data out of AD.

Now one of the things I wanted to read out was to see if the account was locked or if its password never expired. I couldn’t find these entries in AD but after searching those entries are stored in “useraccountcontrol”. But when I looked it was just a number. How does that number tell you if the account is locked?

On the above link is how that number is generated and once I understood that I got to work on writing a PHP script which translates that number into something more usable. Once I wrote the script I put it up on the Hot Scripts Forum to see if the code I wrote could be improved on and optimised. Here is what they came back with:

$userAccountArray = array(
‘NOT_USED_8000′ => 0,
‘NOT_USED_4000′ => 0,
‘NOT_USED_4′ => 0,

function ADUserAccountControl($val) {
global $userAccountArray;
$x = pow(2, count($userAccountArray) – 1);
foreach($userAccountArray as $k => $v) {
if(($val – $x) >= 0){
$userAccountArray[$k] = 1;
$val -= $x;
} else {
$userAccountArray[$k] = 0;
$x = $x / 2;

Simply pass your useraccountcontrol value to the function and read the results out of the array.

WSUS – Unable to connect to the server yourserver.yourdomain

Recently at work we installed the latest version of Windows Server Update Services (WSUS) but we had a few issues with installing it. When installing we were getting the error: Unable to connect to the server yourserver.yourdomain. My work colleague spent hours searching forums and help topics but nowhere had the answer. In the end all it appeared to be was drive compression! WSUS will not install or function if the place where it stores the updates is compressed. To turn off, right click the folder where you’re installing to, properties, click advanced button. On the new window that opens un-tick the box “Compress content to save disk space”. You will notice folders and files that are compressed when the names are in blue. Hope this helps you.

Make Portable/Removable Hard Drive/Memory Stick Bootable

I’m not going to babble on here because if you have found this post you just want to know how it’s done.

Here is what you need:

A portable/removable hard drive/memory stick (USB) that is capable of being made into a bootable device. Some of these devices cant be made bootable; if you are unsure if yours can be made bootable then contact the manufacture. I have successfully made portable Maxtor, Western Digital and Freecom USB hard drives bootable ranging from 40GB to 320GB in size. I have also made a handful of generic USB sticks bootable ranging from 512MB to 8GB in size so it should be unlikely you will have a device that cannot be made bootable.

You will need a computer that can boot from a USB device.

You will also need an existing boot disk of some sort. I find what works best is a Windows 95 boot disk. If you are going to use a floppy or CD then you can get images from

So now lets get prepped! Now we are going to use a fat32 partition for our boot partition. Now the max size for fat32 partition on Windows 95 is, have a guess, 32GB so if you have a portable drive that is 320GB then you will need 2 partitions. The second partition can be NTFS and can fill up the rest of the drive, but the first partition must be fat32 less than 32GB. Just as a side note will tell you what cluster size to use depending on what size your partition is.

Now have you set up your Windows 95 boot disk? If you have downloaded the ISO then burn it to a CD and if you have downloaded the diskette image then run it and get the image on the floppy disk.

Shutdown your PC and insert floppy/CD and plug in your USB device. I would recommend you unplug any other hard drives in your system so that you don’t have any confusion later on and so that you don’t accidentally break your windows install on your PC.

Tell your PC to boot from floppy or CD and wait for Windows 95 to start. You will be presented with:


Now type fdisk and hit enter:


What you are going to do here is set your USB device to the active partition this should be under option 2 on fdisk (This is the FAT32 partition). Once you have set the partition to active you should now see a capital A on that partition. Press escape a couple of times and you will be prompted to reboot. So go ahead and do that, then boot back into your floppy or CD.

Now your USB drive should be set as C: so type dir C:

[code]A:>dir C:[/code]

You should see no files and it should tell you the space available of that drive, it should match the size of the partition. Now lets copy the contents of the floppy or CD to your USB device. Type copy *.* C:\*

[code]A:>copy *.* C:\*[/code]

Once that has coppied type in sys C:

[code]A:>sys C:[/code]

This copies the system info to the USB device. Now just need to set up a Master Boot Record so type fdisk /mbr

[code]A:>fdisk /mbr[/code]

Ok so we are all done now, so reboot and try booting up off your USB device. Now you should see your usual A:&amp;gt; just as if you booted off CD or Floppy.

So that’s about it, you can load up a load of useful DOS utilities. If your using a hard drive with an NTFS partition you might want to put on your new bootable USB device a program called NTFS4DOS. This will give you access to NTFS partitions from DOS. Also another handy utility is Ghost. This will allow you to take an image of any hard drive and put it in one handy file. With that one file you can then restore that image, ideal for taking an image of a fresh install of and operating system and then restoring when you come to reinstall. This will save you having to redo the windows install and reinstall all your software, patches and user preferences.

So there we have it, if you have any problems or want to know more just leave a comment and I will get back to you ASAP.

Windows XP explorer.exe missing or corrupt

So here’s a new one, recently at work we have had a number of XP Pro machines login but failed to load up explorer. The first thing you would attempt would be to start task manager (Ctrl+Alt+Delete), start a new task and start explorer. Now when we did that we were getting an error saying that explorer was missing or corrupt. So we opened up CMD to browse the Windows directory only to find explorer was there and seemed fine…

We came across a fix to rename explorer to explorer2.exe and update the registry with regedit to point to the new explorer2.exe. This worked and proved there was nothing corrupt or missing but it wasn’t an ideal solution as it was quite long winded.

The problem started to appear with more and more PC’s on our network, this is no longer a coincidence. The problem is happening on different service packs of SP so we know its not an SP related issue. After doing a bit of searching around I found something called FixO. After running this and rebooting the PC explorer was now working great and it kept explorer as same name etc. You can get it here: FixO – Repair explorer.exe

Still this was a long way around script but at least it can be scripted into the login script. Anyway one of my work colleges found another solution, which seems to cure the problem but no idea why. It’s a simple one-line registry edit.

Open notepad and put the following in:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\explorer.exe]

Save the file as a reg file. Then run this file in regedit, this simply removes the offending registry key that is causing problems. If you want you can just get the file here: Reg Fix – Fix No Desktop

So we still don’t know what’s causing this but we do have a temporary solution.

Javascript Same Height Div’s Update

A while back I posted a way of making same height div’s but came across an issue when padding was involved. Well I’ve modified my code to take into account padding. Now the obvious thing to do would be to be to check padding on a div and subtract it from the height, but it’s not that easy. You would have to check three things: padding, paddingTop and paddingBottom. For some reason when I was checking padding I couldn’t get a value from JavaScript, this had me really stumped but after a nights sleep I came up with a better and more simpler way of sorting the padding issue. This is to let the code run and let it re-height the div’s and let the padding mess things up then run the same thing again and check for height differences from last time we checked. Oooohhh look the height has gone up 10px from last time thanks to a padding of 5px on the div. Now we know there is 10px of padding lets remove it. Sorted!

JavaScript Code:
function sameHeight(divs) // Bring in an array of your divs
var highest = 0;
var heighttu = 0;
for(i = 0; i < divs.length; i++) // Loop through the divs { // Check to see if this div is the highest? if(document.getElementById(divs[i]).offsetHeight > highest)
// Yes its the highest so set the highest value to this div’s height
highest = document.getElementById(divs[i]).offsetHeight;
// Loop through divs and set their hieght all the same
for(i = 0; i < divs.length; i++) { document.getElementById(divs[i]).style.height = highest+"px"; } // now get offset hieght again and we may found we have gone higher this is because of padding if(document.getElementById(divs[0]).offsetHeight > highest)
// correct the height
highest = highest – (document.getElementById(divs[0]).offsetHeight – highest);
// Correct divs
for(i = 0; i < divs.length; i++) { document.getElementById(divs[i]).style.height = highest+”px”; } } }[/js]

Javascript Same Height Div’s

Recently I had to make some divs the same height. Usually I would just pad the bottom of a div with page breaks but I couldn’t do that this time round as the page content is dynamic and the height of the divs could change.

First thing I did was look online for answers and sure enough there were solutions but looking at them they seemed over complicated so I decided to write my own solution.

Javascript Code:

Update at:

Simply pass an array of your divs to the function. Easy peasy….

Just an extra word of warning… Be aware of using padding on the blocks you pass to this function. If the paddings are different in each block then they may not end up being the same height. Although you could modify the function to check for the use of padding and alter the heights accordingly.

Getting Windows HDD usage with PHP and SNMP

At work a couple of months back I was faced with a problem that many of our servers would run out of hard drive space without us knowing and that would cause the server to hang and/or stop responding. So I did a bit of research and came across. This little utilility would run on the server in command line and tell you what drives were available and some info of the drives like space used and available. Well with this I would echo out the data to a text file and send that across to a common holding ground. Then from there get my web server to constantly scan this folder for new logs. This method worked but it had its issues.

Well yesterday at work I was playing around with SNMP and after finding a site with W2K MIBS I found lots of info you can pull from the server. Now I was already familiar with SNMP in PHP thanks to their documentation on their site. So using their snmpwalk function I was able to pull the relevant data to get HDD usage info.

$names = snmpwalk($row['ip'], “public”, ‘.′);
$used = snmpwalk($row['ip'], “public”, ‘.′);
$total = snmpwalk($row['ip'], “public”, ‘.′);
$alloc = snmpwalk($row['ip'], “public”, ‘.′);

Now that would give me an array of drive names, space used on those drives, total space available on those drives and the allocation units. Now the allocation units I didn’t realize I needed as I thought the numbers given in used and total were just measured in bytes but they aren’t. The numbers in used and total are how many blocks of allocation size (if that makes sense). So to get the true byte value from used and total you need to multiply them by the allocation size number.

25599569 * 4096 = 104855834624B = 97.65GB

So there you have it. Now you know how to get HDD usage from your server using PHP and SNMP.

PHP File Upload Progress Bar Part 2

After further investigation PHP 5.2.0 now allows you to use the APC (Alternative PHP Cache) addition with the ability to track the progress of uploads. Within windows it is as simply adding the dll extension to your php.ini and putting some configs there to. With Linux I’m not too sure how you add this extension as I don’t know Linux well. But anyway below is some nice and easy documentation on this.

PHP File Upload Progress Bar