Compact or Resize VHD file

If you are using dynamic disk for your virtual machine you will soon find out how annoying it is when it grows in size, but when removing the files the disk does not shrink back down. VirtualBox provides tools for compacting a vhdi file but not for vhd. Hyper-v claims to be able to compact, but this often does not work and is also very slow. The solution is to use the built in all powerful Windows Disk Manager.

Run an administrative command prompt
Type “Diskpart” (No Quotes)
Type the following commands:
select vdisk File="I:\path\to\your.vhd"
attach vdisk readonly
compact vdisk
detach vdisk

Only takes a couple of minutes and compacts your vhd file to the expected size. No need to mess about with defrag, zeroing out the drive. Just quick and simple.


Install Windows on a DEDIBOX XC C2750 Avoton at

May only be an Atom Chip, but with 8 cores clocked at 2.4 GHz it is more than capable as a server. is offering these with 8GB EEC RAM for just 20 EURO’s a month.

Board Information:

A1SA2-2750F Motherboard from Supermicro

However for a budget server, you will want to install your own version of Windows Server, using your existing Bizspark or Dreamspark license key. However like most providers do not provide a simple way to use your own key, so the setup has to be completed via KVM.

Installation of windows via their KVM over IP
To install Windows using your own media and license key, you must install from your own media using KVM. (Remember this option does not show up until you have installed an OS. So just install Debian first, and then complete you will find the option.)

On the KVM website select Remote Control | Console Redirection | Launch Console. (This will use a JAVA Viewer)

Next add in your media. Select Virtual Media | Virtual Storage


Change Logical Drive Type to “ISO File”. Browse to your .iso file and then “Plug in”. This will now be available to the remote machine.

Next start your install process. Note this can take a long time. The Windows Server 2012 image is over 4GB, so it takes some time to copy the files it needs from that image to the server for the installation.

Once installed, there is no network connections because Windows is unable to automatically recognise the network controllers.


This .iso file can be mounted in same way as the windows media was.


Install “Intel PRO Network Connections Drivers” | “Install Drivers and Software”

Once setup, windows can use the network interface and should get you your ip. Remote desktop can now be enabled, and then you are ready to connect to and use your server as normal.


Video in a Video using FFMPEG

Use ffmpeg to overlay a video inside a master video or picture in a picture. This effect can be accomplished using ffmpegs overlay filter command.


For this example I use two videos. A master_video.mp4 1920×1080 and a resized smaller_inner_video.mp4 800×450. The two can be combined with the following command:

>ffmpeg.exe -i master_video.mp4 -vf "movie=smaller_inner_video.mp4[inner]; 
[in][inner] overlay [out]" completed.mp4

To improve the look the inner video can have additional padding to adjust its position. The following is the same as above, except additional padding is added:

>ffmpeg.exe -i master_video.mp4 -vf "movie=smaller_inner_video.mp4[inner]; 
[in][inner] overlay=70:70 [out]" completed.mp4

This produces the following:


You can use the padding, to present the inner video into a different corner as required.

You can use the same technique to combine multiple videos together. Simple string the commands together using the [labels] and semi colons ; to separate the steps. For example:

>ffmpeg.exe -i master_video.mp4 -vf "movie=smaller_inner_video.mp4[inner]; 
movie=smaller_inner_video2.mp4[inner2]; [in][inner] overlay=70:70 [step1]; 
[step1][inner2] overlay=1050:560 [out]" completed.mp4

Will produce something like:


Combining steps

In the above examples I had used a video file that had been resized to the smaller size (800×450). However the resizing of the inner video and the merging onto the master video can be done in one step, rather than having to resize the video first, then do a second ffmpeg command to actually combine the two videos.

>ffmpeg.exe -i master_video.mp4 -vf "movie=smaller_inner_video.mp4, scale=800:-1 [inner]; 
[in][inner] overlay=70:70 [out]" completed.mp4

Notice the (comma) , scale=800:-1 This tells ffmpeg to first of all scale the inner movie to the width of 800. The -1 tells ffmpeg to maintain the aspect ratio.

Combining tasks allows ffmpeg to optimise the process which should reduce the time required to complete an operation. it also saves making additional intermediate files.

Fade out

Unless the videos are both the same length, then the last frame of the inner video will remain until the master video has finished. In this case it is best to use the fade command to improve the display.

>ffmpeg.exe -i master_video.mp4 -vf "movie=smaller_inner_video.mp4,  fade=out:300:30:alpha=1 [inner]; 
 [in][inner] overlay=70:70 [out]" completed.mp4

Again use the comma to add additional filters , fade=out:300:alpha=1 This tells ffmpeg to use the fade out filter. The first number is the start frame, the second number is the number of frames the fade should happen over. The alpha=1 part tells ffmpeg to make the video entirely transparent.

Remember all new lines in the ffmpeg commands above should be ignored. They are only there to improve readability on this page. All the commands were tested on Windows machine using a version of ffmpeg built on March 2013


Windows 8 Firewall Predefined Rules Missing

Sometimes after a virus, the Windows firewall becomes damaged. Often even after removing the virus or the cause of the problem, the firewall rules will still be missing.

Allow app in firewall empty

Even when you try to add a new rule, the predefined template is greyed out, preventing you from selecting it.

Add new rule but predefined greyed out

This means that all rules you require will have to be setup manually. But finding all the ports and the settings to manually setup the rules can be tricky. Even more frustrating, the option in the firewall to “Restore defaults” does not restore the missing rules. However a quick and simple solution is to import a working set of rules from a working windows 8 machine back to the one with the missing rules.

To do this

Step 1: Export from working Windows 8 machine.

Press Windows Key + X. Click on “control panel”. Select “System and Security” then “Windows Firewall”. Next click “Advanced settings” from the action pane on the left. Once there right click on the root item in the left hand menu, and then select “Export Policy”. Save this file and transfer to the windows machine you wish to fix.

Step 2: Import policy file.

Press Windows Key + X. Click on “control panel”. Select “System and Security” then “Windows Firewall”. Next click “Advanced settings” from the action pane on the left. Once there right click on the root item in the left hand menu, and then select “Import Policy”.


You will get a popup warning saying that any existing rules will be deleted. But as you do not have any, this is nothing to worry about.

Once done you should now have a full set of Firewall Rules setup, which you can choose to enable or disable as you require.


Windows 7 Product Key not available

Without a windows 7 product key, windows disables functionality.


This could be because of corruption of the license store, or because your current trial of windows has expired. To fix this first recreate license store. Press start, then type cmd. Right click on the application that is found, and select Run As Administrator.

Then type net stop sppsvc (this will stop the Software Protection Service)


cd %windir%\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform


rename tokens.dat


cd %windir%\system32

Then restart the Software Protection Service

net start sppsvc



This will then have reset your activation. You may be asked to enter your key in. If you do not yet have a key then you can temporarily use a default key to give you a 30 day trial. However you can not enter a default key using the activation window as it immediately tries to activate the code, which will obviously not work. So to enter the default key close the activation window, again open the command prompt (cmd) with Run As Administrator.  Then enter the command: slmgr /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

Substitute the X marks with a default product key that matches your version of windows below.


Professional – HYF8J-CVRMY-CM74G-RPHKF-PW487

Home Premium – RHPQ2-RMFJH-74XYM-BH4JX-XM76F


Starter – 7Q28W-FT9PC-CMMYT-WHMY2-89M6G

After a reboot windows will then enter into its 30 day trial mode, enabling full functionality within Windows.





Run Virtual PC in Windows 8 bypass compatibility assistant

Windows 8 no longer allows Virtual PC 2007 to be installed. Attempts to install Virtual PC 2007 will bring up the Program Compatibility Assistant saying This program has compatibility issues which prevent installation. Virtual PC 2007 has been removed because Windows 8 now comes with its own inbuilt virtualisation software Hyper-V. However this requires your CPU to support SLAT, which many older processors do not.


To install Virtual PC 2007 you can disable the Program Compatibility Assistant. To do this you need open the Group Policy Editor.

Press Win + R and then enter “gpedit.msc”


The two options to enable are found here:

Computer Configuration -> Administrative Templates -> Windows Components -> Application Compatibility

You need to enable both Application Compatibility Engine and Program Compatibility Assistant.

registry options

You then need to Reboot your machine for the change to take affect.

Last step, simple involves renaming the setup file you downloaded. e.g. change setup.exe to setup2.exe.

Now when you go to install Virtual PC you will bypass the Compatibility restriction. (Although I would recommend after installation restoring the Program Compatibility Assistant)

Below is a screenshot showing Virtual PC running on my Windows 8 test machine.

windows 8 and virtual pc


Display YouTube user avatar profile picture by username

With YouTube there is no easy url you can use like[username] which can return the users current image. The only way to get the users image is to call one of YouTube api feeds[username]

The image url returned is only of the current image, so if the user changes there profile image, then you will keep displaying the old image, so you can’t even just store this value as you need to check the feed each time. But to call this url and process it server side will consumer server resource and delay the time that the page can be sent to the user. Best to make the loading of the picture happen client side via a little bit of JavaScript.

The YouTube api call[username] can be customised to return only the fields you need. e.g.[username]?fields=yt:username,media:thumbnail,title

It can then be further customised to return json and have it wrapped inside a script tag.


Next you can add in a callback script that should be called. e.g.[username]?fields=yt:username,media:thumbnail,title&alt=json-in-script&format=5&callback=showYouTubeProfileInfo

This will return a .js file which will contain the data values you needed with a function call to the name you specified in the callback field, making it easy to process the returned information. Example:

// API callback
showYouTubeProfileInfo({"version":"1.0","encoding":"UTF-8","entry":{"xmlns":"","xmlns$media":"","xmlns$yt":"","title":{"$t":"Daniel Mitchell","type":"text"},"media$thumbnail":{"url":""},"yt$username":{"$t":"[username]"}}});

Putting that all together, place the following code into the head of the document.

Then in the body place the following code:

That’s it, just change [username] to the username you want to get the details for and you will have a client side display of the YouTube users info.

If it all works it should display something a little like this:

profile picture


Prevent Windows 8 restarting after installing updates

After Windows install new updates it popups the message above to inform you that it IS going to restart, yet there is no option, no choice to stop this from happening. This can be an issue when running on a production server or when you are using the computer for work.

There is however a small tweak that can be made that prevents this option from happening. Two methods, using the Local Group Policy Editor or using the registry.

Using the Local Group Policy Editor

Press Windows + R to bring up run box. Type gpedit.msc. Then browse to:

Computer Configuration\Administrative Templates\Windows Components\Windows Update

Then need to change the option “No auto-restart with logged on users for scheduled automatic updates installations” from “Not configured” to “Enabled”.


That’s it. Although unhelpfully it says you need to restart yoru computer for the changes to take affect, which is the very thing we are tying to avoid. But to make the changes take affect straight away run the command gpudate /force to force the changes to take affect straight away.


Using the Registry

Some version of Windows 8 do not come with the Local Group Policy Editor so you have to make the change via the registry.

Press Windows + R to bring up run box. Type regedt32. Then browse to:


If the above location does not yet exist you may have to create the keys WindowsUpdate and AU.

Then add a new DWORD (32-bit) Value with the name of NoAutoRebootWithLoggedOnUsers and giving it a Hexadecimal value of 1.


Reboot and then its done. Now updates will continue to be installed but the restart will only take place when YOU choose to.


Reset Windows 7 Rearm Count

An install of Windows 7 without an activation key allows for 30 days of usage. This can however be extended up to 120 days by using the following slmgr (Software Licensing Management Tool) command to rearm or reset the 30 day trial.

slmgr /rearm

(Remember to run this command, you must right click on cmd and select “Run as administrator” for this to work) However this can only be done up to 4 times. You can view the number of rearm counts by using the command which displays the current license information:

slmgr /dlv



Notice the second to last line shows that I only have 1 more remaining rearm, after which the software will expire. However there is a small trick that allows you to reset the rearm count back to 4. To do this you need delete the registry key which contains the Last Rearm Time, however this key can not be deleted or modified during a normal user session. To delete the key you will need to run the following commands in the windows recovery console.

reg load HKLM\MY_SYSTEM "%~dp0Windows\System32\config\system"
reg delete HKLM\MY_SYSTEM\WPA /f
reg unload HKLM\MY_SYSTEM

To do this save the above commands to a .bat file ‘reset.bat’ to the C:\ root folder. Restart your computer, pressing F8 to get to the Advanced Boot Options. Select the option to Repair Your Computer. Select your keyboard input method. Login with your login details. In the System Recovery Options menu, select Command Prompt. Now type in C:\reset.bat. (If it says “‘C:\reset.bat’ is not a recognised as in internal or external command” message, then it may be because the  C Drive is bring used as a recovery partition. Try again using D:\reset.bat) If successfully you should get the message “The operation completed successfully”. Next reboot your machines.

After rebooting you may get a message stating that this product is not genuine. This can be ignored. Running slmgr /dlv again will confirm that the rearm count has been increased again, thereby giving you another 120 days worth of windows use.



Facebook – Non Expiring Access Tokens

With changes to Facebook authentication last year, the ability to request a non expiring access_token has been lost. This is less than ideal when writing apps that wants to post on behalf of users, without having to continually keep asking for their permission, or to do so when the user is not present.

However there is a couple of tricks that enable you to still get around this.

1) Posting to Personal Timeline.

To post to personal timeline, you do not need a users access token, but instead get the user to add your app, then you can you use the apps access_token (which does not expire) in order to make posts.

2) Posting to Pages

This is more tricky, as your app is not added to the page but only to the users personal pages. Therefore you need to use the users access_token, but even after extending it, the token returned will expire after 60 days.

A useful tool to check the expiry date of an access_token when testing is provided by Facebook here:


Here after extending the access token, Facebook returns me a 60 day access token.

Making users have to log back in every 2 months would be a hassle, and could result in posts not being made. To get a non expiring token make a request for the Page Access Token.


This will return a page access_token, however what is of more interest is that the user token originally returned has now had its expiry changed.

facebook-access-token-expiry-neverThis user access_token previously obtained can now be used to post to pages owned by the user.




This functionality is confirmed on Facebook at:

By using a long-lived user access token, querying the [User ID]/accounts endpoint will now provide page access tokens that do not expire for pages that a user manages. This will also apply when querying with a non-expiring user access token obtained through the deprecated offline_access permission.

So to have continuous access to post to users timelines and pages:

  1. Have user add your application with appropriate permissions: “publish_stream, manage_pages” – This will enable your application access_token to post at anytime.
  2. Call the endpoint [User ID]/accounts or [Page ID]?fields=access_token. – This will then convert the user token to a non expiring token which can be used to post to the users pages at anytime.