Saturday, December 25, 2010

How to solve “My PC Randomly Wakes up from Sleep”

Whenever your PC wakes up, Windows keeps a log of why. To view, open a command line and run:

 C:\> powercfg -lastwake
Wake History Count - 1
Wake History [0]
  Wake Source Count - 1
  Wake Source [0]
    Type: Wake Timer
    Owner: [PROCESS] \Device\HarddiskVolume3\Windows\System32\services.exe
    Owner Supplied Reason: Windows will execute '\Microsoft\Windows\Media Center\mcupdate_scheduled' scheduled task that requested waking the computer.

As you can see, my computer woke up because of a scheduled task. Open the Task Scheduler: image And navigate to the task in question (\Microsoft\Windows\Media Center\mcupdate_scheduled, in my case). On the Conditions tab, uncheck wake: image

Friday, December 24, 2010

Why Developers Always Need to use UTC

Assert.AreEqual(new DateTime(2010, 11, 07, 06, 0, 0, DateTimeKind.Utc).ToLocalTime(),
new DateTime(2010, 11, 07, 07, 0, 0, DateTimeKind.Utc).ToLocalTime());

Because when we fall back from Daylight Saving Time, the hour of 1am is repeated, making it ambiguous. Which is why the above test code passes in Central time, since 6am and 7am UTC are both 1am, one 1am CDT, the other 1am CST.

Monday, December 13, 2010

Using XML Namespaces in PowerShell

$xpath = @{
    Start="//e:data[@name = 'BootStartTime']/text()"
    End="//e:data[@name = 'BootEndTime']/text()"
}

$ns = New-Object Xml.XmlNamespaceManager $xml.NameTable
$ns.AddNamespace( "e", "http://schemas.microsoft.com/win/2004/08/events/event" )

[DateTime]$Start = $xml.SelectSingleNode( $xpath.Start, $ns ).Value
[DateTime]$End   = $xml.SelectSingleNode( $xpath.End, $ns ).Value

($End - $Start).ToString() # Displays: 00:03:11.7917783

Via.

Wednesday, December 08, 2010

Full IIS Mode at Windows Azure

One of the nice new features in the December 2010 release 1.3 of the Azure tools is Full IIS Mode, the ability to run multiple web sites in a single Azure web role. The documentation is a bit sparse still, but the short answer is to add multiple <site/> tags in the ServiceDefinition.csdef.

Here's a good post on the Azure blog, and here's some documentation at MSDN.


<Site name="<web-site-name>" physicalDirectory="<directory-path>">
   <Bindings>
      <Binding name="<name-of-the-binding>" endpointName="<endpoint-identifier>" hostHeader="<url-of-the-website>" />
   </Bindings>
</Site>