Preventing a certain Windows Update from installing on Windows 10

TL;DR this post explains how to prevent a certain update from installing on a Windows 10 machine (at the time of writing, build 10049). The information below might not be accurate/relevant for future updates.

During its preview, Windows 10 does not allow (by default), changing how updates are installed. It was possible to modify this using various Group Policy settings and a bit of registry tweaking, but since build 10049 it no longer works – it’s not possible to restore the “old” Windows Update applet in Control Panel.

On my machine (HP EliteBook 8570w), an update for the Synaptics TouchPad drivers took away my middle button, it simply did not appear anymore on the TouchPad properties. Uninstalling the update, and installing the Windows 8.1 Synaptics driver from the HP website helped, but within a day it was automatically updated again.

An answer on SuperUser suggested disabling all automatic driver updates, but I didn’t want to do that. Luckily, I found a way to disable this particular update despite Windows Update settings were not changeable with a wonderful set of PowerShell tools called Windows Update PowerShell Module.

Here’s how to install the PowerShell module and disable unwanted Windows Updates:

1. Download the Windows Update PowerShell Module, and extract it to either

%USERPROFILE%\Documents\WindowsPowerShell\Modules

or

%WINDIR%\System32\WindowsPowerShell\v1.0\Modules

(the former does not require elevation)

2. Temporary disable Execution Policy, to allow importing unsigned scripts. From an elevated PowerShell console type

Set-ExecutionPolicy Unrestricted -Force

followed by:

Import-Module PSWindowsUpdate

After the module had been imported, restore the Execution Policy to a reasonable setting, such as RemoteSigned.

3. Uninstall the unwanted update (if installed), then run the following command to get a list of all available windows updates:

PS > Get-WUList

ComputerName Status KB          Size Title
------------ ------ --          ---- -----
LAMBDACORE   D-----            65 MB Synaptics driver update for Synaptics SMBus TouchPad
LAMBDACORE   D----- KB2956185  68 MB Update for Microsoft OneDrive for Business (KB2956185) 64-Bit Edition
LAMBDACORE   D----- KB2965255  11 MB Update for Microsoft Office 2013 (KB2965255) 64-Bit Edition
...

4. Hide the “Synaptics driver update” by issuing the following command:

PS > Hide-WUUpdate -Title "Synaptics driver*"

ComputerName Status KB          Size Title
------------ ------ --          ---- -----
LAMBDACORE   D--H--            65 MB Synaptics driver update for Synaptics SMBus TouchPad

The letter H now signifying that the update is hidden! That’s it, the update will now be hidden from Windows Updates, and won’t be installed. To unhide, run:

PS > Hide-WUUpdate -Title "Synaptics driver*" -HideStatus:$false

Now, all I have to do is change the two-finger scroll direction, and I can get back to work!

Adding a custom property page to existing project types in Visual Studio

Note: this post assumes some knowledge developing Visual Studio Extensions (VSIX).

Suppose you’re developing custom tooling that enhances (or otherwise modifies) current project types (for example, C# class libraries or Web applications). This is most commonly done by specifying custom MSBuild properties, typically by adding a .targets file to the project file itself (possibly via NuGet, which can import .targets files automatically).

One common way to interact with those custom properties is by adding a page in the project properties, however, most documentation about extending project properties refers to creating your own project systems. Any documentation about extending existing projects is either out of date, or nonexistent.

But, when there’s a will – there’s a way. TL;DR: Here’s how to add a custom property page to a regular C# console application:

  1. Create an (empty) VSIX project
  2. Add a reference to the following assemblies: Microsoft.VisualStudio.AppDesigner.dll (located in the GAC), and Microsoft.VisualStudio.ManagedInterfaces.dll (from the Visual Studio SDK)
  3. Create a new class that derives from Microsoft.VisualStudio.Editors.PropertyPages.PropPageBase
  4. Implement the class as follows:
[ComVisible(true)]
[Guid("some-guid")]
[ProvideObject(typeof(MyPropertyPageProvider))]
public class MyPropertyPageProvider : PropPageBase
{
    protected override Type ControlType
    {
        get { return typeof(MyPropertyPageControl); }
    }

    protected override string Title
    { 
        get { return "My Property Page"; } 
    }

    protected override Control CreateControl()
    {
        return new MyPropertyPageControl();
    }
}

Make sure to provide a new GUID in the GuidAttribute (tip: if you use ReSharper, you can create new GUIDs on the fly by typing nguid and pressing Tab), we will need this GUID again soon. Specify the title of your property page, and provide an instance of a UserControl-derived (WinForms, baby!) page that will be the UI. Visual Studio provides an abstract Microsoft.VisualStudio.Editors.PropertyPages.PropPageUserControlBase class you can derive from.

 Important: Visual Studio will try reading the size of the control from the assembly’s compiled resources – this requires a .resx file for the user control. Best to create a new User Control using the Add – User Control context menu (so it can have a .Designer and a .resx files), and change the base type to PropPageUserControlBase afterwards.

One last piece of the puzzle is hooking it up – this is where a bit of MSBuild magic comes in. After running your extension (in the Experimental Instance), create a new, say, C# Console application. When the project is created, open its .csproj file in Notepad (or your favorite editor), and add the following property into one of the PropertyGroups (or create your own PropertyGroup, e.g.):

<PropertyGroup>
  <CfgPropertyPagesGuidsAddCSharp>{some-guid}</CfgPropertyPagesGuidsAddCSharp>
</PropertyGroup>

Using the GUID from before. Save the .csproj file, and when you reload it in Visual Studio, you will now have a brand new (albeit empty) property page in the project’s properties!

(You can probably add this property dynamically with DTE from your extension, instead of modifying existing projects, but I haven’t tried it.)

So what happened? Where did CfgPropertyPagesGuidsAddCSharp come from, and what makes it so special? Turns out, after a long investigation, it’s an undocumented property, which is a part of the legacy C# and VB project systems. When Visual Studio processes C# or VB projects, it will look for this property, and attempt to instantiate the COM class at a given GUID. If successful, it will add it as a property page.

I was able to confirm this works in Visual Studio 2013 and 2015, not sure about the earlier editions.

So there you have it, a bit of undocumented functionality makes the impossible possible Smile

Happy hacking!

Disabling certain “invisibles” in the Atom Editor

I recently started using GitHub’s Atom editor, and other than the slow-ish startup time, I love it very much!

One of the things I hate most is redundant whitespaces, so in all editors I use, I try to work with visible whitespace enabled, so I can keep those tiny dots in check. In the Atom editor, this feature is called Show Invisibles, however by default it shows all the invisible characters, including endof and newline characters. There’s no UI (yet?) to toggle which ones you want to see, but luckily, Atom is completely “hackable”, allowing us to do change about anything!

To remove the EOL/newline characters, go to File → Open your Config. The configuration file will open in a new tab, where you can modify the invisibles: entry like so:

"*":
  editor:
    invisibles: 
      eol: false
      cr: false
    ...

Upon saving the file, Atom will immediately reload the configuration, and only the whitespace dots will remain visible!

For more information about what can be changed, check out Customizing Atom.

A case of mysterious spam links!

Update: I was rightly corrected by the creator of μBlock, those are not links, but CSS selectors inside a <style> tag, to cause the offending links to be removed from the page. Furthermore, those particular rules are being fed from AdBlock Plus’ EasyList, and they are not related to μBlock.

I was tweaking a Jekyll theme to match the style of our Bootstrap-based site, when I suddenly noticed an alarming links to porn/spam sites, visible inside Chrome tools:

Alarmed, I didn’t know what to make of this at first. It’s a custom (paid) Bootstrap theme, so I suspected either the theme or one of its plugins was the culprit, however I could not find any code that seemed to inject this particular style.

Armed with fairly little knowledge of dealing with web development, I decided to try and set a breakpoint inside the Chrome tools on the text inside the <style> element itself, by right-clicking and selecting Break on… → Subtree modifications:

I reloaded the page and then found myself inside a script called contentscript-start.js, which turned out to belong to μBlock:

Thanks to George Pollard (@porges) I was led to this issue on the uBlock github, where it seemingly replaces all instances of http://face* with a matching filter (which, in this case, a link to a porn site). The reason for this is still unclear to me, as face* generates way more false positives (i.e. facebook).

This also explains the other link: the bottom of my Bootstrap page contains a link to the Facebook and LinkedIn pages. uBlock must be matching http://link* as well.

So if you find those while looking at your site through Chrome dev tools, don’t be alarmed as I was – it’s just your friendly neighborly adblock in action!

How to get changed files from SVN between two revisions with PowerShell

As part of teaching myself PowerShell (and converting a legacy mess of perl scripts into something more manageable), I needed a way to export the files that were added or modified between two SVN revisions. After some searching, I came up with this PowerShell script: it takes a repository URL, a from and to revision numbers, and an output directory into which to export the files.

This script uses Resolve-FullPath cmdlet from the Carbon project. Turns out, PowerShell’s own Resolve-Path doesn’t work on files/paths that do not exist.

Here’s how it works:

  1. It executes svn diff command with –r switch, which takes a range of revisions, e.g. 1000:1050. The summarize argument shows only the high-level information, and xml outputs the data as XML.
  2. This XML is being queried with an XPath, extracting only the names of the items of kind ‘file’ which were ‘added’ or ‘modified’.
  3. For every such file, its relative path is being taken by subtracting the repository path from the full filename.
  4. The target (sub)directory for that file is being created, if it doesn’t exist.
  5. It then executes svn export command on the current filename, limiting it to the to revision, so that  the changes are taken only until that revision. The file is written in the relative target directory.

This is far from “idiomatic” PowerShell, but it gets the job done! Your improvements are welcome, feel free to comment on the Gist!

The 2-minute PowerShell intro for someone who “hates PowerShell”

Hi, I’m a developer, and I hate PowerShell*. For no reason in particular, PowerShell just never seemed that appealing for me as a developer, as it was always marketed towards sysadmins. And I never liked the syntax – all those dollar signs reminded me of PHP.

This recently changed, however. A client had a set of legacy perl scripts which nobody could maintain anymore – and I was tasked with rewriting them. Having recently spent some time writing a script for Boxstarter – an amazing tool that allows you to automate software and environment installations of new machines, powered by Chocolatey, in PowerShell, I thought that it could be a good fit for the task. I knew the language is powerful enough to allow the creation of those very useful tools, so I decided to give it a shot. I was not disappointed!

Luckily, you already have all the tools you need to get started! Every Windows machine comes with both PowerShell and PowerShell ISE (Integrated Scripting Environment) already installed.

PowerShell ISE
Figure 1: PowerShell ISE – an IDE for PowerShell with code completion (IntelliSense) and an integrated debugger.

Here’s what you need to know about PowerShell:

You can do most of your development and debugging in the ISE – no need to type individual instructions in the PowerShell console. It’s great as a REPL, but nothing beats an IDE. Tip: select a few lines in the ISE and press F8 – only those lines will be executed!

What’s so great about PowerShell?

It’s dynamic – every variable can be treated as anything, but also support explicit typing (which are checked at runtime). Variables are prefixed with the $ sign.

$my = "some string"
$my = 23

# Runtime error: Cannot convert value "23" to type "System.Xml.XmlDocument"
[xml]$myXml = $my 

It’s pipelined – every variable or the output of every function can be piped as an input to another function using the pipe (“|”) operator. It’s extremely useful when dealing with collections and other enumerable objects – allowing you to filter the elements and transform the result into whatever you need.

# a LINQ-like querying with pipelining. 
# The $_ is similar to C#'s lambda argument "x", e.g. Where(x => x.Name == "chrome") 
$ids = Get-Process | Where-Object {$_.Name -eq "chrome" } | Select-Object -Property ID 

# Where-Object and Select-Object can also be written "where" and "select": 
$ids = Get-Process | where {$_.Name -like "chrome" } | select -Property ID 
# "where" and "select" are aliases. Use Get-Alias to see all aliases in PowerShell.

It supports everything you know from .NET – although PowerShell defines its own idioms with regards to common operations, such as formatting strings for joining paths, you can use all objects from .NET to do the same thing.

$combined = Join-Path $rootDirectory "mySubdirectory" 
# can be written as: $combined = [System.IO.Path]::Combine($rootDirectory, "mySubdirectory")

It’s concise – everything in PowerShell can be verbose or very concise. By leveraging aliases there are many ways to say what you mean. Here’s an example: the following function gets a list of changed files between two SVN revisions, by executing the svn diff command, outputting the result as XML which looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<diff>
<paths>
<path
   item="added"
   props="none"
   kind="file">hello.txt</path>
<path
   item="modified"
   props="none"
   kind="file">other.txt</path>   
</paths>
</diff>

This XML is stored into an $output object, which is defined as a .NET XmlDocument. The object is than being queried via XPath to get only items of kind ‘file’ which are ‘modified’. Finally, only the text of the node is selected.

function Get-SvnDiff($fromRevision, $toRevision)
{
  [xml]$output = & svn diff -r $("{0}:{1}" -f $fromRevision, $toRevision) --summarize --xml
  $output.SelectNodes("/diff/paths/path[@item='modified' and @kind='file']") | % { $_."#text"}
}

Quite a lot is going on in this example, which demonstrate the Power of PowerShell:

  • A process is started with the & symbol. Can also be started with Start-Process for more options.
  • Strings can be formatted with –f, however in this case they are a part of an expression, and have to be escaped into their own expression by using $().
  • The % symbol is an alias of foreach, which is an alias of ForEach-Object. Use Get-Alias -Definition ForEach-Object to see all the alias definitions, or Get-Alias %, for example.
  • The last line in a function (or selection) is what gets returned (or printed out). In this case, the result of the last line is a single string, containing the value ‘other.txt’ (it’s the only modified file). If there was more than one result, the return would be an array.
  • Finally, to call this method, we use Get-SvnDiff 1000 2000, and we can use the pipe operator (“|”) to continue modifying the returned values.

And that’s it! Sure, there is way more to know about PowerShell, but this should be more than enough to get started, or at least, not to get lost when reading and writing simple scripts.

Happy scripting!


  • Well, slightly less now.

My top 3 favorite Windows productivity tools!

There are way more tools I love and use every day, but the following 3 are my must-haves on every Windows machine I use, so I wanted to share them with you. And they are completely free!

(Ok, there are actually 4 – the first one, Chocolatey is a pre-requisite to the others. Chocolatey is a package manager, like apt-get, but made with Windows in mind. If you haven’t already, install this first! I’ll wait.)

#1 – Rapid Environment Editor (RapidEE)

C:\> choco install Devbox-RapidEE

RapidEE is an editor for the Windows environment variables! No more being stuck squinting in the unresizeable Windows dialog, this tool will not only let you add, search and modify envvars easily, it will also show invalid paths in red, letting you find dead entries quickly!

#2 – Everything

C:\> choco install Everything

Imagine a list view, with a search box at the top, and nothing else, which finds any file in your computer immediately – you have just imagined Everything. This lightweight search engine indexes your entire hard drive(s) in seconds after installing, letting you then find any file, anywhere! My preference is to bind the shortcut for a New Window to Ctrl-Shift-Z, so I can pop open Everything everywhere with this single chord. Set it under Tools – Options – Keyboard.

#3 – Ditto

C:\> choco install ditto

Ditto is a clipboard manager for Windows. If you ever used ReSharper’s Clipboard Manager you will appreciate this little tool – it remembers every single Ctrl-C you’ve ever done, allowing you to paste back any item at any time! The default shortcut for Ditto is Ctrl-`, and it is packed with features, such as searching, exporting and removing entries, with full unicode support and ability to sync clipboards between machines. What’s more, it supports “smart paste”, allowing you to paste entries in places such as the Windows Command Prompt, which will only support proper copying and pasting only in Windows 10.

Code, music and single malt whisky!