Windows Performance Counter Types

There are several types of performance counters in Windows. However, I had a hard time of understanding all these types just from their documentation. So I decided to compile some examples for each counter type.

I also wrote some C# code to demonstrate how to use performance counters. You’ll find it at the end of this article.

Read more →

Switching OpenID providers through delegation

Back in the days, when I decided to join StackOverflow, I was forced to create an OpenID – because this is the way to login on StackOverflow.

I decided to use an independent OpenID provider, called myOpenID. I also set up OpenID delegation. This way I could use my own domain name as my OpenID. (OpenID uses URLs as user names, like http://manski.net.)

Now, myOpenID is shutting down on Feburary 1, 2014. Thus, I had to switch my OpenID provider.

Fortunately, OpenID delegation makes this easy – you just replace the two delegation <link> tags and you’re done.

Unfortunately, not all OpenID providers seem to support this. I tried Google (which should work according to this), but StackOverflow always wanted to create a new account for me. (May also be StackOverflow’s fault, I don’t know.)

Fortunately, StackOverflow provides its own OpenID service:

https://openid.stackexchange.com/

So I created a new OpenID there, replaced the <link> tags (details), done. Works like a charm.

Disable UAC in Windows 8

In Windows 8, Microsoft changed the UAC slider’s lowest setting from “Disable UAC” to “Hide UAC”.

So, even with the lowest setting programs will still not run with Administrator privileges (like in Windows 7).

Windows' "Run" dialog with UAC still active.
Windows’ "Run" dialog with UAC still active.

To disable UAC, execute this PowerShell script as Administrator (e.g. via powershell from an Admin Command Prompt):

Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System" -Name "EnableLUA" -Value "0"

After that restart and UAC is disabled.

Windows' "Run" dialog with UAC disabled.
Windows’ "Run" dialog with UAC disabled.

Notes:

  • Only do this, if you’re aware of the consequences. Disabling UAC may make the system less secure.
  • The Windows 8 Store can’t be used anymore if UAC is disabled. (You can, especially, no longer installed Windows 8.1.)
  • To reenable UAC, use -Value "1" in the command above.

LINQ to SQL – bits and pieces

In a project I’m currently working on we’re using LINQ to SQL. While most of it is straight forward, there are some quirks that are not that obvious (at least to me).

This article is mostly a FAQ but I will explain some of the not-so-obvious features in more detail.

Note: I’m not going to explain how to setup the connection to the database in this article. I’m assuming that this already works.

Read more →

Calculate return value for sort by int

Most programming languages (such as C#, Java, …) allow you to sort lists. Most of them also allow you to specify a sorting function so that you can customize the sort order. These functions usually take parameters a and b and define the return value as follows:

Return value if
less than zero a is less than b
equals zero a is equal to b
greater than zero a is greater than b

Usually you would do something like this (code in C#):

int Compare(int a, int b) {
  if (a < b) {
    return -1;
  }
  else if (a > b) {
    return 1;
  }
  else {
    return 0;
  }
}

However, when comparing int values, there’s a much quicker way to do this:

int Compare(int a, int b) {
  return a - b;
}

That’s it.

Note: Care should be taken if a and/or b can come close to int.MaxValue or int.MinValue. In this case the results may not be what one wants (like if a = int.MinValue and b = 1 then the result will be int.MaxValue which is wrong obviously).