Categories
geek programming tips windows

global autocorrect in Windows

Autocorrect or auto-replace is a great productivity tool. You can use it to automatically fix misspelled words (“teh” instead of “the”), or have it autocomplete stuff like “krg” to “Kind regards, n3wjack”. Word and Outlook have it built in, and Vim has it too, but it’s kind of annoying that you have to set it up everywhere, and that some tools simply don’t support it.

Wouldn’t it be great if you could have autocorrect working everywhere in Windows? Enter AutoHotkey!
This neat little tool allows you to set up autocorrect replacements that work in any text entry field. They work in Notepad, VS Code, even in text areas in your browser.

Once installed, you right-click the program icon in your system tray and choose “Edit This Script” to edit the active script. Add something like this to add some auto-replace rules:

::teh::the
::rg::Regards,{enter}n3wjack
::krg::Kind regards,{enter}n3wjack
:::flip::(╯°□°)╯︵ ┻━┻
::Lorem1::Lorem ipsum dolor sit amet, consectetur adipiscing elit...

You get the idea. The ::‘s are used to indicate you’re setting up AutoHotkey “hotstrings”. Simply put, it will auto-replace the first bit, with the last bit. There are more details in the excellent manual.

Afterward, save the file and choose “Reload This Script” on the system tray icon. Your autocorrects will now be available anywhere in Windows.

AutoHotkey is a full-blown automation tool, btw. The autocorrection is just a small tip of the iceberg. If you want to learn more, check out the manual to see what you can do with its scripting language.

Categories
geek linux microsoft programming software tips tools ubuntu windows

WSL setup, tips and tricks

WSL or Windows Subsystem for Linux allows you to run a fully functional Linux environment, inside your Windows 10 system, without having to set up a virtual machine. It’s a lot more lightweight too, and it integrates nicely with the Windows OS, so it’s a great way to explore Linux, or use the two systems side by side for cross-platform development. This also skips the need for setting up Cygwin and whatever hacky way to access those Linux command line tools on Windows.

I’ve been using it for a while, so I’ll list a short setup guide here, and some tips & tricks to help you along.

Installing WSL

Installing WSL is really easy now. Just open an administrator PowerShell or a Command window and type:

wsl --install

That will install WSL with the default Ubuntu distribution. If you prefer something else, like Debian, you can use this command:

wsl --install -d Debian

The username and password for your WSL system is specific to the Linux distribution. So make sure you don’t forget that password. :)

There are 2 versions of WSL. If you can, run on v2. It’s faster, better and euhm, harder? Anyway, it’s faster, so that’s what you want. But sometimes, you might want to run things on v1 anyway. For example, some VPN clients break with the WSL v2 networking. The easiest way is to set your WSL distro to v1, and see if that works. It did the trick in my case with the CheckPoint VPN on my work machine.

To check your WSL version, run:

wsl -l -v

It should show something like this, if you’re on Debian and v2

  NAME                   STATE           VERSION
* Debian                 Stopped         2

To switch the Debian distro to v1, you can run this:

wsl --set-version Debian 1

Makes sense right? But you just have to know.
Switching versions can take a while as it’s being converted, so do this when you have the time for it.

Accessing your files in WSL

Ok, now let’s do some work in WSL, by typing wsl in a PowerShell window.

That’s it, you now have a shell in your local WSL system.
You’ll see something like this on your prompt:

n3wjack@Mjolnir:/mnt/c/Users/n3wjack$

That’s a mount of your Windows C-drive into the Linux system. So you can access any file from your Windows system in your Linux shell. The other way around also works.

Open up an Explorer window and enter \\wsl$ in the address bar and hit return.
You’ll see a folder pop up for each WSL distribution you have installed. So if you’ve installed Debian, you’ll see a Debian folder. From there you can access any file on your WSL system.

Windows Explorere windows showing the Debian distribution folder under the \\wsl$ network drive.

Keep in mind that this cross OS file access is pretty slow, certainly for lots of small files. So if you are planning on working on files, it’s better to choose your OS and stick with it. But it’s super handy that you can easily copy and access files from any system.

Installing software in WSL

Well, this is easy. If you’ve installed Debian or Ubuntu, so you probably know you can install more software using apt or apt-get.
WSL pretty much behaves as it should, and you can just install whatever you like using known tools.
The account you created when setting up your distro is an administrator account, so you can use sudo commands.

Moving your WSL distro to a new PC

So you have your Linux distro all set up the way you want to, and now you’ve got yourself a brand new shiny piece of hardware to work and play on. How do you move that WSL distro over to the new machine?
Luckily, it’s as simple as backup and restore. Really. It’s actually easier than moving your Windows files over.

Creating a backup of WSL works like this:

wsl --export <distribution> <filename.tar>

So if you see that your distro is called Debian after running wsl -l -v, you do this:

wsl --export Debian debian.tar

This takes a while. After it’s done, you copy the tar file over to your new shiny machine and run the following command:

wsl --import <distribution name> <install path> <tar file path>

Or actually:


wsl --import Debian c:\users\YourName\AppData\Local\Packages\Debian c:\temp\debian.tar

That’s it! You now have your full distro moved to a new machine, including all settings and files.

For more info on WSL, see the excellent official Microsoft documentation.

Categories
software tips tools windows

wake up Windows automatically using a scheduled task

This seems easy at first, but it turns out to be a lot harder than expected, due to various OS and power settings that get in the way. The idea is simple: you want to have your Windows 10 machine start up at a specific time using a task set in the task scheduler.

When you create a new task in the Task Scheduler, there’s a setting for this, so it looks so easy. It’s on the conditions tab. You activate the option to wake the computer to execute your task, and you’re done. Right? Well, if you’re really lucky that might work straight out of the box.
In case it doesn’t work, here are some things you can fiddle with to try and get it going.

  1. Create a wake-up tasks that doesn’t really do anything. Just run a command like this:
    cmd /c echo %date%
    For a more detailed guide on how to set up a task and the wake timers check this excellent article.
  2. Create a second task that does what you want it to do in a batch script but 10 minutes later than the first. That gives your computer ample time to start up, install any potential updates, or do whatever it sometimes does that takes so damn long.
  3. Deactivate Fast Startup. It messes with your hibernation mode and causes it not to startup again afterwards.
  4. Always hibernate your machine. If you just do a plain shutdown it doesn’t seem to automatically start up again. You can do this with the command below. This is also handy if you want to shut your machine down again, after your task has finished:
    shutdown /h
  5. Enable wake timers in your Power Options advanced settings. See the link below for instructions.
  6. For laptops make sure your Power Options are configured correctly. Mind closing the lid in that case. A closed lid will prevent the laptop from starting up in my case for example. Laptops will also not startup when they are running on the battery by default.
  7. Reboot your machine after fiddling with these settings if it still doesn’t work. This makes sure your settings stick.
  8. If you tried everything and it still doesn’t work, check your BIOS settings and see if there might be a power option in there that might prevent it from starting up automatically.

Give your machine a few minutes if you’re testing this. Yes, it’s annoying to wait, but if you set it too fast, it might not be powered down fast enough to be able to start up again, and miss the timer. That way you won’t be able to tell if it’s actually working.

Hopefully you can now use your desktop or laptop to run some nightly scheduled jobs, without having to have a dedicated always-on machine around. Saves you time and money on power consumption, hardware and maintenance!

Categories
geek microsoft tips windows

how to stop windows 10 from rearranging your desktop icons

I’m a desktop minimalist myself and the trashcan is about all I want to see on my desktop. However if you like your desktop with lots of icons on it, arranged according to some non-alphabetical grouping system you might find out that Windows sometimes rearranges them nicely in alphabetical order, aligning them all nicely to the top left of your desktop without your prior consent.
This typically happens after reboots, switching between resolutions, plugging and unplugging a secondary screen or docking/un-docking the laptop.
It can drive people mad.

This seems to be an issue that has been plaguing Windows 8 and 10 for quite a while already, driving lot’s of people bonkers. Unfortunately when looking for a solution online in various fora you tend to find a lot of useless tips or the suggestion to install some third-party desktop icon position-saving software. Eew.

There is a simple solution in the Windows settings however, but I have to admit it’s not very obvious and I had to look for it quite a bit to find it.

It’s all in the settings as expected, but it’s spread out in two different spots, which makes it hard to get right.

Here’s how to fix it:

1. Right click on your desktop and disable the auto arrange feature by disabling the checkbox next in View > Auto arrange icons.

Shows how to disable the auto arrange icons feature in Windows.

You’d think that should do the trick right? Well most people do. But there’s another option that interferes with your desktop icon zen garden staying the way you want it.

2. Right click again on your desktop, now click Personalize.
You’ll see the Settings screen appear.
There you select Themes.
Now click Desktop icon settings.
Now look what we have there. A checkbox labeled “Allow themes to change desktop icons“.

Uncheck it and press OK.

You should now no longer experience the frustration of computer code messing with your desktop icons.

Zen at last.

Disable the Allow themes to change desktop icons checkbox

 

Categories
geek windows

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.