Category Archives: microsoft

erase free space on an SSD drive

DeleteAs you probably know (because you’re reading this post) Windows doesn’t really destroy a file when it is deleted. It merely removes the references in the file table so you don’t see it in on the file system anymore. But the file is still intact sitting there on your hard drive until some other file is written over it.
If you want to truly erase those files on a HDD drive you can use a number of tools to erase the free space on the drive. What these tools do is simply overwrite all free space with random data and thus effectively overwriting and destroying those deleted files still sitting intact in your free disk space.
Free tools that can do this are the command line Secure Delete tool from System Internals and the handy CCleaner (see the tools menu).

For an SSD drive however overwriting the free space with random data is bad for your drive. SSD’s have a limited number of times you can write data to their blocks. Using a random data overwrite tool, which can even end up do this multiple times, is just a bad idea.

Luckily everything is built into your SSD drive to do this automatically. It’s called the TRIM function and from Windows 7 on this is activated by default so normally you don’t have to do a thing to take advantage of this secure-delete feature.

However if you are like me then you want to be sure if this feature is activated.
On Windows, you can do this by opening a command prompt and entering the following command:

fsutil behavior query disabledeletenotify

If you get the following, your TRIM command is already active on Windows:

NTFS DisableDeleteNotify = 0

If this would return a value of 1, you can activate the TRIM function with this command:

fsutil behavior set DisableDeleteNotify 0

You can find more detailed instructions and information about activating the TRIM function here:
How to check if TRIM is enabled on your SSD and how to enable it
Why SSD TRIM support is so important and how to enable it

And then there’s always Google of course.

how to move an unreachable window on windows 7, 8 or 10

arrowsOn the “good” old XP this required some trickery and knowledge of window specific shortcuts, but on more recent version of Windows this has become really easy to do.

So if you run into a situation where an application’s window is outside your visible area, because you disconnected a second screen for example and the app doesn’t automatically snap to the only screen left, simply do this:

  • Keep the Windows key pressed and hit the cursor key left or right.

Your window will simply snap back to your current screen and all is well.
Using it with the up & down arrow will maximize or minimize the active window. Always handy to know those shortcuts if you have both hands on the keyboard anyway.

Photo by Dean Hochman, cc-licensed.

mstsc.exe crashes on Windows 8 (and how to fix it)

Physical View of the Network

When using MSTSC (Microsoft Terminal Server Client aka RDP or Remote Desktop on Windows) to dial into a local HyperV virtual machine on my laptop it often happened that MSTSC crashed on me. When reconnecting afterwards, the VM was running just fine. So it seemed to be an issue on my local machine and not the VM. I assumed it had something to do with HyperV and RDP and didn’t look into it any further (I didn’t need it that much after all).

The exception code I got in my Event Viewer for the crash was 0xc0000005 on ntdll.dll.

But then I kept having this problem so often when connecting to a physical machine in the network it annoyed me enough to Google for a possible solution.
One post pointed me in the right direction (which I can’t find anymore, sorry about that), being that it had something to do with sharing of local resources. In my case I recently activated the option to transfer sound between the remote and my local machine so I could use Skype & Linq.

Turns out that was indeed the culprit. Whenever my remote machine made a sound, my RDP client crashed. Bummer!
Turning off sound transferring to my host machine made the crashes go away. Sweet!

So if you also run into this, try turning off some of those local resources.

It still sucks if you need sound of course, but in my case, I can live with the silence.

Photo by Robin Gist, cc-licensed.

chocolatey package update quick reference

gingerbread2011_18

Chocolatey rocks when it comes to updating a bunch of installed software from the command line. If you’re not doing that often however it can be hard to remember exactly what commands you can use to do that quickly. So here’s a little run-down on the most helpful commands when you are updating your system.

First you might want to check what’s installed on your machine.
You can get the list of the local package Chocolatey installed like this:

chocolatey list -localonly

or in short:

clist -localonly

To check if any package have updates available, we can run the update all statement, but not quite for real yet. By adding the -whatif switch, Chocolatey only pretends to update:

chocolatey update all -whatif

or:

cup all -whatif

Ready to update all packages at once? Nice. So let’s disable those confirmation prompts while we’re at it too by adding the -y switch.

chocolatey update all -y

or

cup all -y

Photo by elidr, cc-licensed.

why an open sourced .NET framework is huge

free

I was already excited about the recent ASP.NET vNext developments. Things like the fact that you can get the ASP.NET source code on Github, that it’s completely FOSS and that it’s disconnected from the rest of the .NET stack are just plain awesome.

A huge step for ASP.NET vNext is that you don’t need Visual Studio to write software with it. You can use your favourite text editor like Vim, Sublime, Emacs or whatever you like, together with a number of open source command line tools.

A second huge thing is that ASP.NET 5 can now run cross-platform using Mono on Linux and Mac. Not only can you use your development tools of choice to write and build your C# code, you can also do it on the OS of your choice. .NET everywhere. Think about it. *mind blown*

Yesterday however, things got even sweeter as Microsoft is now releasing more of the v5 .NET Framework as open source. This means more and easier cross-platform development and Mono compatibility (as the source can be easily integrated in Mono) for .NET code.

On top of that there is now a new Visual Studio Community edition of Visual Studio available for free. This is equal to the Pro version, so you can ditch those crippled free “Express” versions and write code in the tools you’re used to professionally. I love this one. I’ve messed around with SharpDevelop and the Express version, but if you’re used to the “real thing” it feels like having to work with your hands tied behind your back.

As if this wasn’t enough there’s a bunch of other cool improvements too, like getting only the .NET framework components you need for your project and pull them in using NuGet. Scott Hanselman sums them up nicely.

So if you’ve always wanted to check out .NET or C# but didn’t want to because you had to run it on Windows and in Visual Studio, there’s nothing holding you back any more. For .NET developers this is great. It gives us more freedom than ever without having to learn a new language and framework. For people hacking away on OS X and Ubuntu with Ruby, Python etc. because they want to use FOSS, this is an opportunity to dip into the wealth of .NET resources out there and try something new.

The strategy is clear. They want everyone to use the .NET framework, they want everybody to run that code on Azure (even if you’re not using .NET) and they see that making it open is the only way to get there. Great times are ahead.

how to update chocolatey

I use Chocolatey all the time to quickly install software on Windows machines. At some point Chocolatey itself also gets an upgrade, which just happened recently and then I can never remember how to get Chocolatey itself upgraded.

It’s in the documentation somewhere I’m sure, but since Chocolatey is about easily installing and upgrading Windows software, it was bound to work “recursively”.

So here’s how you do that from a Windows shell prompt, for (my) future reference:

    c:\> chocolatey update chocolatey

speeding up your TFS CI builds

Entering Hyperspace

If you’re using TFS as your build server for CI builds of .NET projects, you want your CI build to be bleeding fast so devs don’t sit around waiting until their build completes. This is even more the case if you use a gated check-in on that CI build.

The ideal time frame is less than 5 minutes, but as a solution grows and more projects are added it gets hard to stay below that time limit without tweaking the build. With a CI build in this case I mean a build used to check if all code compiles, is integrated with other code and all unit tests pass on it.
This build is not used for deployment. There should be a separate build for that.

So what are the time sinks here in a standard TFS build?

It helps if you know what’s it’s doing, even though it’s pretty straightforward. First your code is fetched from TFS. A local workspace is used on the build server and all files are retrieved. Then the VS solutions build with MSBuild. Code analysis is performed if requested, unit tests run, outputs are copied to your drop folder and build reports are published.

Here are a number of things you can do to speed this up:

  • Get only the latest changes, not the full code base every time by not completely cleaning up the workspace. If you only clean up the outputs, it takes a lot less time to update the workspace. The more code you have, the more this counts.
  • Code analysis is CPU intensive and slows down your build significantly. Make sure you set this to “as configured” in your build configuration, so it doesn’t run on projects that you don’t want analysed. Then configure your projects in Visual Studio that need CA, and disable it for the rest.
  • In the Source and symbol server settings, set “Index sources” to false for the CI build. This feature includes source information into your PDB files which makes things easier to debug later on, but since we’re building strictly for a CI build we don’t need this data afterwards.
  • Disable copying output files to the drop folder. The output of the CI build shouldn’t be used for any deployments, so this can all be skipped to speed up the build.
  • Look for slow tests. Often these are integration-like tests which will be causing disk I/O by manipulating files or accessing a database etc. You can disable them for the CI build only by adding a TestCategory attribute called “Integration” (or whatever you like) and exclude those from the build in the test settings. Another trick is to put all your integration tests in a separate assembly and exclude the tests from running using the test assembly file pattern.  E.g. With *.Test.dll project Foo’s Foo.Test.dll is included, but Foo.IntegrationTest.dll isn’t.
  • Avoid lots of small projects in your solution. Every project will take a few extra seconds to build, so merging them into a single larger project will build faster. Make good use of namespaces instead. For example one assembly for unit tests (or 2 if you take that integration test project in mind) is better than a test project for each regular project.

Pick and choose as needed, but these should give you a considerable boost.
Remember to analyse your build before starting to tweak it. There’s no point in optimizing what’s fast as hell already. A good tool to check out what’s taking so long is the open source TFS Build Explorer. It shows your build steps in a tree-view, including timing info and is a hell of a lot quicker than the default build output from TFS for big builds. Depending on your TFS server version you might have to use an older executable, but they are all available in the download section.

Photo by Éole Wind, cc-licensed.