David Kennedy’s Tech Ramblings

Just another WordPress.com weblog

Handy trick for disabling Aero in your applications November 13, 2009

Filed under: Uncategorized — dotnetdave @ 9:24 am

Having only recently moved to the 64bit fold following the purchase of a new PC, I’ve just come across the following useful trick to disable Aero. (Discovered on http://www.codeproject.com/KB/vista/controllingaero.aspx) If you want to ensure compatibility with Vista/Win7 users, or you are having problems as a result of Aero (for example, some DirectX function calls may fail if Aero is active on the desktop running your app) then the following may come in very handy:

    public static class AeroController
        public static readonly uint DWM_EC_DISABLECOMPOSITION = 0;
        public static readonly uint DWM_EC_ENABLECOMPOSITION = 1;
        [DllImport("dwmapi.dll", EntryPoint = "DwmEnableComposition")]
        extern static uint WinDwmEnableComposition(uint uCompositionAction);
        /// <summary>
        /// Enables or Disables Aero on Vista or Win7, required for some compatibility issues
        /// </summary>
        /// <param name="enable">if set to <c>true</c> [enable].</param>
        /// <returns></returns>
        public static bool ControlAero(bool enable)
                if (enable)
                if (!enable)

                return true;
            catch { return false; }

Once added to your project, you can then simply enable/disable Aero with a call such as:


My Dual-boot nightmare (and a procedure to shrink partition/LVM2/ext4) November 7, 2009

Filed under: Uncategorized — dotnetdave @ 10:10 pm

Yesterday I decided to install Windows 7 natively, aiming for a dual-boot between Fedora 11 & Win 7. Obviously I was aware that windows installers always wipe the MBR with its own boot loader, destroying any loader which plays well with others (just about any OS besides Windows), so I took backups of the MBR (both with and without the partition table, or so I thought):

dd if=/dev/hda of=/home/David/mbr_backup_nopart bs=446 count=1  (just the MBR without the partition table)
I copied this file to a USB memory stick so I would be able to access it following the Win7 install

I then performed the following procedure (worked perfectly) to shrink file systems, logical volumes, and finally the physical partitions:
  1. Boot to any linux Live CD (I used Ubuntu, if your Live CD doesn’t automatically give you sudoer, authenticate as root and drop the ‘sudo’ prefixes)
  2. sudo lvm vgchange -a y (enable logical volume management, since my Fedora install uses LVM2)
  3. sudo fsck -fC /dev/vg_davesdualcore/lv_root (check the file system which I am about to resize)
  4. sudo resize2fs -p /dev/vg_davesdualcore/lv_root  250G (shrink the ext4 file system to use half my hard drive)
  5. sudo lvresize /dev/vg_davesdualcore/lv_root –size 250G (shrink the logical volume accordingly)
  6. sudo lvs (to report the size of your logical volumes, we are after the size of the /swap volume)
  7. sudo lvremove /dev/vg_davesdualcore/lv_swap (remove the swap volume so it can be recreated at the start of the newly available space)
  8. sudo lvcreate –size 3.8G –name lv_swap vg_davesdualcore (recreate the swap partition)
  9. sudo mkswap /dev/vg_davesdualcore/lv_swap (set up a linux swap area on the re-created volume)
  10. sudo pvs (report use and calculate the size the partition can be reduced to, ie. PSize – PFree)
  11. sudo pvresize /dev/sda2 –setphysicalvolumesize 254G (resize the physical volume to free up space at the end of the partition)
  12. sudo pvs –units s  (list physical volumes with size specified in sectors, note PSize)
  13. sudo parted /dev/sda unit s print (print the physical disk partitions with Start, End, & Size in sectors)
  14. Calculate the new End sector (Start from step 13 + PSize from step 12, add at least 32MB/65536 sectors as an error margin)
  15. sudo parted /dev/sda rm 2 (Remove the entry from the partition table. The number is the partition number as listed from step 13)
  16. sudo parted /dev/sda mkpart primary 409663s 533487742s (recreate the partition with the original Start & newly calculate End from step 14)
  17. sudo parted /dev/sda set 2 lvm on (enable logical volume management, again the number is the partition number)
  18. Done! You can view your new structure with ‘parted /dev/sda print’ and/or ‘fdisk -l /dev/sda’
Following this, I inserted a Windows 7 Pro DVD & rebooted. The windows installation completed successfully and I ended up with a working windows 7.

Now, as mentioned at the start of this blog post, the windows installation wiped the MBR. And this is where my nightmare begins..
I attempted to restore the MBR using the following shell command from an Ubuntu Live CD:
(STORE N GO is the volume name of the memory stick I used)

dd if=/media/STORE\'N\'GO/mbr_backup_nopart of=/dev/sda bs=446 count=1
And rebooted..
Much to my dismay I was greeted with the 'Invalid System Disk' message. Fedora 11 still boots following this message however (guess its some sort of BIOS fail-over mechanism), but I am so far unable to get Windows 7 booting from GRUB
When I restored the MBR, it apparently reverted the size of my PV to use most of the disk space again. I re-ran pvresize to set this back, but no luck on the Windows 7 front yet. Looks like I might be up for a complete re-install after all 😦