File Hashing Is Built Into Windows

Note: This post was updated on 08/08/2021 to include instructions for PowerShell.

I always used to download the md5sum.exe and sha1sum.exe files when I needed to generate a file’s hash in Windows.

I just discovered that certutil.exe, included with Windows 7 and Windows Server 2008 R2 (and later), will do this for you (I’m not sure if it was included in earlier versions of Windows).

Hashing with cmd.exe

Just use the following commands in a cmd.exe shell to generate the appropriate hash:

  • MD5:   certutil -hashfile C:\Windows\notepad.exe MD5
  • SHA-1:   certutil -hashfile C:\Windows\notepad.exe SHA1
  • SHA-256: certutil -hashfile C:\Windows\notepad.exe SHA256
  • SHA-512: certutil -hashfile C:\Windows\notepad.exe SHA512

Note that it defaults to SHA-1 if you do not specify a hashing algorithm.

Also note that in Windows 10 (and possibly earlier), the MD2, MD4, MD5, SHA1, SHA256, SHA384, SHA512values are all valid for the algorithm parameter.

Hashing with PowerShell

To get similar functionality in PowerShell, use the following command.

Get-FileHash -Algorithm <algorithm> -Path <filename>

For example, to get Notepad’s SHA-256 hash, you would run the following:

Get-FileHash -Algorithm SHA256 -Path C:\Windows\notepad.exe

Making Image Backgrounds Transparent with Paint.Net

I found this solution on the getpaint.net web site:

  • I use the Bucket (fill) with a full transparent color.
    • Set the foreground to white and fully transparent, i.e. RGB all = 255, Transparency – Alpha = 0
    • Set the background to white and not transparent, i.e. RGB all = 255, Transparency – Alpha = 255
  • You have to change the tool parameters from “Normal blend” to “Overwrite” in advance, or you won’t see any effect.
    • Tool = Bucket Fill
    • Flood Mode = Contiguous
    • Fill = Solid Color
    • Tolerance = 17%
    • Antialiasing = Enabled
    • Overwrite
  • You can access the parameters after choosing the bucket. Press the little chemical bottle icon, in the right to the fill tolerance slider.

Visual Studio 2010 / SP1 / Windows SDK Install Order

When you plan to install the Windows 7/2008 R2 SDK, the SDK needs to be installed before VS2010 SP1.  Here is the recommended install order:

1. Visual Studio 2010
2. Windows SDK 7.1
3. Visual Studio 2010 SP1
4. Visual C++ 2010 SP1 Compiler Update for the Windows SDK 7.1

Here is the link to the blog post about this: http://blogs.msdn.com/b/vcblog/archive/2011/03/31/10148110.aspx

Unit Testing Private Static Methods in C#

I had never needed to unit test a private static class method in C# before, but it turns out that Microsoft created a special object type to handle just such a case.

To test the private static method DetermineFilename (that takes filePath as a string parameter and returns a string) in the FileManager class, do the following:

Thanks to Venkat for posting this solution on his web site here:
http://venkatcsharpinterview.blogspot.com/2011/07/unit-testing-private-static-method-in-c.html

Get SQL Server Version/Edition Information

Just connect to the database in which you are interested, open a new query window, and enter the following query:

For me, this produced the following:

Load more