Category Archives: geek

class not registered error in PowerShell on commandlet

I ran into this weird COM component error trying to run a commandlet from an IIS administration module.

Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6}
 failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_
 CLASSNOTREG)).

The module imported fine and I could list the available commandlets and get help on them. So everything seemed to be installed properly. It just turned out that I was running the command on the wrong platform.

Or to be more exact, I ran the command in a 32-bit mode Powershell instance while I should have been in a 64 bit version. The COM component that was called is a 64 bit one, and that didn’t sit well with the 32-bit Powershell instance.

So how do you see what version of Powershell you’re in? Find out by running this statement , which returns true or false:

[Environment]::Is64BitProcess

Now that you know what mode you’re in, try the other one. You should have both in your Start Menu, where the 32-bit one has (x86) appended to the name. In my case that did the trick.

Windows search results for Powershell shows all versions available of the PS shell.

 

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.

Photo by Delete, cc-licensed.

disable flash and silverlight for safer surfing

Flash, Silverlight and (*gasp*) QuickTime plugins in your browser with the modern web are about as necessary as a horse whip is on a Tesla. Well I might be exaggerating a bit. There are still some useful sites out there that actually use these things. Intranet sites that run on IE only for example, or flaky game sites. But any self-respecting web developer has long ditched them in favor of fancy new HTML5 features.

So why would you still run these things in your favorite browser (Firefox right?) where they only take up extra memory and have a bunch of security problems that might end up causing you trouble. There have been enough exploits for the Flash plugin out there to be sure to actually update those plugins every time they ask for it. Which is about every week if I recall correctly.

Anyway, it’s better to turns those damn things off completely and only turn them on when you hit one of those web sites maintained by a dinosaur. That way you’re stopping that evil hacker from taking over your machine with his Flash exploit and you’re gaining some free performance along the way.

In Firefox you can turn those plugins off in your Tools menu, under Add-ons. Just select “Never activate” and you’ll be fine.
Switch it back to “Ask to Activate” if you’d need them again. That way they’ll never activate by accident either, if you forget to turn it back off.
On Chrome it’s a bit more elaborate, but the option “Let me choose when to run plugin content” sounds like a safe bet instead of having plugin code be ran willy-nilly.
IE? Ha! Who cares right?! For anything else, a properly aimed search query should find you the answer in no time.

Oh, and don’t forget to tweak your Flash security settings if you decide to keep it on after all.

The Firefox add-in screen with all plugins disabled. Just like it should be.

ip-cam considerations

Security Camera SystemsIP cams are great. They keep an infrared eye on your stuff while you’re not around and find out what keeps pooping on your driveway (a cat it turns out). But sometimes things can get a little out of hand.

So here’s a list of things that will trigger the IP cam motion detection you didn’t think of:

  • Cats parading on your driveway like they own the place.
  • Spiders shaking their arachnid booty in front of the camera while doing their webbing thing.
  • Spider webs moving in the wind, up close. All f-ing night.
  • The occasional bird.
  • The occasional insect in mid-flight. Sometimes even a mot at night caught in the infrared beams.
  • Trees and bushes shaking their leaves and branches cause it’s windy as hell.
  • Shadows of trees and bushes shaking their leaves and breanches because it’s windy as hell and sunny too.
  • Rain showers. Possibly in combination with freaky winds blowing it horizontally in places you didn’t think rain could get at.
  • The sun playing peekaboo with some clouds, causing abrupt changes in light levels.
  • Car headlights lighting up random bushes, walls and other stuff as they pass by your house.
  • Reflections of cats in the cars shiny exterior (what a great excuse for not washing your car).
  • Reflections of moving clouds in a puddle on the concrete at the right lighting conditions.

So watch out where and how you send those automated alert emails from the camera. GMail for example doesn’t like it when you send hundreds of emails a day using one account. They find it rather spammy. When this happens, they can block you from sending any more messages that day. This really blows if you have an urgent mail to send. Other mail providers have similar rules.
Uploading the images to a remote FTP server is another option. But make sure you have plenty of space there, and download those images regularly if you don’t want to run out of space.

Photo by Armend Krasniqi, cc-licensed.

indent selected lines with tab in vim

.vimrcOne thing that annoyed me about using Vim was how much keystrokes it took to indent or un-indent a few selected lines of code. My (probably less than ideal) way of doing that was to go into visual mode, select the lines with the movement keys J or K, then use the keys to change the indenting which are < or >.
To indent another level, pressing dot after this would work.

In Visual Studio or a typical Windows text editor I’m used to simply selecting the lines by holding shift & moving the cursor keys up or down, then pressing TAB to indent and shift-TAB to un-indent.

I’m so used to using the cursor keys for text manipulation that it’s hard to unlearn this, so I was looking for key mappings to do the same thing in Vim.
Luckily this turned out to be rather easy. If you add the following to your vimrc file, you can shift-tab away to indent your code:

" TAB-mappings to allow indenting of selected text instead of using < & >
vnoremap <Tab> >
vnoremap <S-Tab> <

warmup your site or wordpress blog with a single command line statement

mother

GNU Wget is a powerful tool when it comes to downloading files from the web or mirroring sites. It’s command line features can be daunting and not very obvious. With some experimentation, reading the (f..) manual and some Googling you can get it to do some pretty neat tricks for you.
All of that is from the command line too, which is great if you want to schedule this kind of magic or use it in a script.

For example, you might want to warm-up your site or WordPress blog so your homepage and all posts linked from it are present in your cache when a visitor arrives. I’m assuming you are using a caching on your site otherwise this is pretty pointless. For WordPress you can use a caching plugin like W3 Total Cache for example.

With Wget, it goes like this:

wget.exe http://n3wjack.net --spider --no-directories --level=1 --recursive 
         --accept-regex=n3wjack.net/20[1..9].*

The command line parameters (in order) mean something like:

  1. Crawl n3wjack.net.
  2. Crawl it like a spider (follow the links).
  3. Don’t create directories for downloads.
  4. Crawl 1 level deep (so anything linked on the homepage is OK, but don’t go deeper).
  5. Do this recursively (so it actually goes 1 level deep).
  6. Follow only links that start with "/201..." to "/209..." (it’s a regular expression).
    This one is a trick to have it only follow links to blog-posts because my URL scheme begins with the year of the post (2015, 2016, …). It’s good until 2099, which should do the trick I guess. :)
    This way I’m also avoiding it loading all tag, category or page links.

If your site has a different URL scheme you’ll have to change the accept regex pattern to fit your scheme.

You can download Wget from the GNU site. It’s Open Source and is available for Windows, Mac and various Unix systems.
For Chocolatey users, there is a wget package available to install it on your system.

verifying an md5 file hash with just powershell

Tools
You see this possibility for a lot of software downloads but if you’re like me you hardly ever end up doing it: verifying an install file’s MD5 or SHA-something hash.
For Open Source software this is however recommended if you aren’t downloaded from the official mirror (and even then) and certainly if it’s anything related to security (like Keepass for example).

But to verify that MD5 hash you probably need to install yet another piece of software you’re hardly going to need, so you end up not bothering at all.

Hold on a second.

If you have a recent Windows system with PowerShell installed, you probably have all you need to verify that MD5 hash.

Try this in the PowerShell command prompt:

Get-FileHash .\KeePass-2.30-Setup.exe -Algorithm md5

It should print out something like this:

Algorithm       Hash
---------       ----
MD5             CD430EB0F108BB192D2155C68EB7BB48

Which happens to be exactly the MD5 hash code listed on the site for that version of the Keepass installer. Yay!
Without that -Algorithm parameter it prints out the SHA-256 hash by default, but that’s longer and harder to compare visually even though it’s more precise.

That was easy and required no additional software.
Pretty damn sweet.

Photo by Julien Dumont, cc-licensed.