Dumb Questions

Friday, 8 November 2013

A car is bogged at Port Parham South Australia in 1951Something I still remember from my school days was one of my teachers telling me, "David, don't be afraid to ask a question!". Presumably I'd been struggling with a particular topic (possibly maths), and essentially they were encouraging me not to sit there "spinning my wheels", but get some help to make sense of the problem.

That's a lesson that's just as applicable today as it was then. In software development, we are constantly solving problems. Some are easy, and some are hard. Some are easy but the hard bit is finding the bit that will be easy to fix.

Sometimes it's just the act of getting a colleague to come and have a look that sheds light on the problem.

But not just in work. Only this week I was at a Church meeting, and people were asking some very deep, insightful questions. I however asked what some might call a "dumb" question (but one which I didn't know the answer, hence why I asked).

After the meeting as I was leaving, a couple of people came up to me and said, "I was wondering the same thing, thanks for asking that!".

Which is another great reason to ask questions, even if you think they're dumb, as odds are someone else is wondering the same thing too.

Photo from Mallala Museum, used under Creative Commons Attribution-NonCommercial 2.0 Generic license

What's waking up my computer at 3am?

Thursday, 17 October 2013

I was working late last night, and when I was done, I chose 'Hibernate' when I was closing my laptop. This morning, I went to grab my laptop and noticed it was warm (with the lid down). Something had caused it to wake up, but what?

First stop, Event Viewer. In the System Log, there's this event:

The system has returned from a low power state.

Sleep Time: ‎2013‎-‎10‎-‎16T14:59:15.107518600Z 
Wake Time: ‎2013‎-‎10‎-‎16T16:44:40.891642600Z

Wake Source: Unknown

Well that's not particularly useful.

I remember previously having a similar problem caused by a scheduled task – so maybe it would be worth checking what scheduled tasks are active and allowed to wake up the computer? You can view all scheduled tasks by opening the Windows Task Scheduler application. The problem is that tasks are listed hierarchically, so you'd need to drill down into every folder and review each task. Maybe PowerShell can do this more efficiently?

Graimer posts a good example of querying scheduled tasks on Stack Overflow.

I've extended it so that I can filter just the tasks with WakeToRun and Enabled both true.

function getTasks($path) {
    $out = @()

    # Get root tasks
    $schedule.GetFolder($path).GetTasks(0) | % {
        $xml = [xml]$_.xml
        $obj = New-Object psobject -Property @{
            "Name" = $_.Name
            "Path" = $_.Path
            "LastRunTime" = $_.LastRunTime
            "NextRunTime" = $_.NextRunTime
            #"WakeToRun" = [bool]::Parse( $xml.Task.Settings.WakeToRun
            #"Enabled" = [bool] $xml.Task.Settings.Enabled
            "Actions" = ($xml.Task.Actions.Exec | % { "$($_.Command) $($_.Arguments)" }) -join "`n"

        if ($xml.Task.Settings.WakeToRun)
            Add-Member -InputObject $obj -Name "WakeToRun" -Value ([bool]::Parse( $xml.Task.Settings.WakeToRun )) -MemberType NoteProperty

        if ($xml.Task.Settings.Enabled)
            Add-Member -InputObject $obj -Name "Enabled" -Value ([bool]::Parse( $xml.Task.Settings.Enabled )) -MemberType NoteProperty

        $out += $obj

    # Get tasks from subfolders
    $schedule.GetFolder($path).GetFolders(0) | % {
        $out += getTasks($_.Path)


$tasks = @()

$schedule = New-Object -ComObject "Schedule.Service"

# Start inventory
$tasks += getTasks("\")

# Close com
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($schedule) | Out-Null
Remove-Variable schedule

# Output all tasks
$tasks | Where-Object { $_.WakeToRun -and $_.Enabled }
(It appears that these extra properties are sometimes null or don't exist, so I had to add them conditionally)

So, what were the results? There were two:

Actions     :  
Path        : \Microsoft\Windows\TaskScheduler\Manual Maintenance
Name        : Manual Maintenance
LastRunTime : 30/12/1899 12:00:00 AM
NextRunTime : 30/12/1899 12:00:00 AM
WakeToRun   : True
Enabled     : True

Actions     :  
Path        : \Microsoft\Windows\TaskScheduler\Regular Maintenance
Name        : Regular Maintenance
LastRunTime : 17/10/2013 8:16:31 AM
NextRunTime : 18/10/2013 3:00:04 AM
WakeToRun   : True
Enabled     : True

I think we can exclude the first, as it has never run. The second looks interesting as the NextRunTime is pretty close to the time that my laptop resumed. I'll change the WakeToRun setting on this task to see if the problem goes away.

Windows 8.1 VPN Settings

Tuesday, 24 September 2013

In Windows 8 after you had configured a VPN, you could right-click on a VPN connection and a context menu gave you two options:

Windows 8 VPN context menu

The second item is really useful when your password for the VPN has changed, and you need to enter the new password.

Upgrading to Windows 8.1, this context menu doesn't seem to exist anymore. It seems that to modify connection properties or credentials, the only option is to search for "Change VPN Settings".

Windows 8.1 VPN Settings

Selecting a VPN connection then enables Edit and Remove buttons. Clicking Edit takes you to the Connection Properties screen, where you can update credentials and VPN proxy settings.

Strange that this is a bit harder under 8.1.

Upgrading to Windows 8.1

Sunday, 15 September 2013

With Microsoft making Windows 8.1 available through MSDN, I thought I'd try upgrading an existing Windows 8 instance. The process was very smooth:

  1. I downloaded the appropriate .iso
  2. Opened the .iso file in Windows 8
  3. Ran setup.exe
  4. Entered license key
  5. Chose to keep existing settings and applications
  6. Wait a while and reboot
  7. Wait a while and then log in
  8. All done

The only problem I've noticed is that connecting the Mail and Calendar apps to an Exchange server with a self-signed certificate no longer works. I'd previously figured out a way to work around this for Windows 8, but it no longer works for 8.1.

Code analysis error CA0055 with a project upgraded to .NET Framework 4.5

Monday, 29 July 2013

I have a Visual Studio solution that was upgraded to use .NET Framework 4.5. It was working fine until I started getting the following error(s) running Code Analysis as part of the build:

CA0052 : No targets were selected

CA0055 : Could not load D:\dev\MySolution\MyProject\bin\Release\MyProject.exe. The following error was encountered while reading module 'System.Xml': Could not resolve type reference: [mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]System.Runtime.CompilerServices.IAsyncStateMachine

That seemed odd, as I confirmed that the application did have an assembly reference to System.Xml. I even tried re-adding the reference but that made no difference. The interesting thing is that the type (IAsyncStateMachine) is new in .NET 4.5, even though it is included in mscorlib Version That’s because 4.5 is an in-place upgrade.

I did notice that you do get separate copies of the reference assemblies located in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework. Reflecting on the mscorlib.dll assembly in the v4.0 folder showed it did NOT have IAsyncStateMachine, but the one in the v4.5 folder did. Could that be relevant?

Opening up the .csproj file, I discovered that another assembly reference suspiciously had the following HintPath defined

<Reference Include="System.Web">

  <HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.dll</HintPath>


Re-adding this reference, resulted in Visual Studio changing it to just this:

<Reference Include="System.Web" />

And then re-building the solution with Code Analysis enabled was successful.