Category Archives: windows

how to safely run destructive sql statements

christmas afternoon

This tip is one of those “Why didn’t I think of that before” things when I saw it being used first. You see, sometimes you’re on this production database and you need to run some SQL statements in Microsoft SQL Management Studio. Statements that if you mess them up will end up ruining your customer’s day, and most certainly yours too.
Of course you’ve already taken a backup, but that isn’t perfect. It takes time to restore those and the most recent changes might be lost. The database might also be humongous, making backup & restore operations rather annoying.

Enter:

BEGIN TRANSACTION

You know this! Before you run any statement doing anything destructive on your database, first run the BEGIN TRANSACTION statement. It feels like spring doesn’t it? With fluffy little bunnies hopping around merrily in the green grass and yellow flowers.
Whatever you run next, nothing will actually happen until you run:

COMMIT TRANSACTION

If in the meanwhile however that delete statement turns out to act like the Spanish Flue and wipes out half of the precious records stored in your database table, there’s always:

ROLLBACK TRANSACTION

Undo. Restore from last save. You don’t lose a life.
Awesome. More fluffy bunnies.

One thing to keep in mind though. As long as your transaction isn’t committed your statements will be putting locks on rows and perhaps even tables. The longer you keep those, the more chance other people’s queries will have to wait for you to release those locks and might even time out. This is bad. So keep your transaction trickery as short as possible.

For more details on those magical statements, see MSDN.

visual studio 2010 becomes slow after saving on Windows 7

Rust and oil inside "Niles machine tool" (HDR)

Ran into this annoying bugger of a problem with Visual Studio 2010 on Windows 7 where every time I saved a file (any file, no matter how large or small it was) the GUI started reacting extremely slow on me. Menu’s didn’t react, keystrokes didn’t appear, scrolling didn’t work. It acted like a whole bunch of stuff was going on, but nothing really was. After a few minutes or so responses where back to normal, until I saved a file again…

While it was happening CPU usage of devenv.exe was fine (very low). Cleaning the solution didn’t help either, which in some cases fixes odd VS behaviour. In short, I was at a loss. Googling for a solution didn’t really bring up a solid answer, until I found a post that mentioned something about jumplists in Windows 7 and VS 2010 being slow. In that post the antivirus software is blamed but that was not the issue in my case, since the issue only started occurring recently without any changes to my setup.

Using the Systems Internals (great tools there btw if you want to dig deeper into your Windows system) file monitoring tool I noticed that a file in a specific path was sort of hanging things. When I looked up the file it did point to those so-called jumplist thingies again. After clearing these shortcut files, VS started acting like normal again.

So, if you’re having issues with a slow VS 2010 on Windows 7 on saving, try clearing the jumplists like this:

  1. Right-click the Start button
  2. Choose Properties
  3. Uncheck both checkboxes under the Privacy group
  4. Click the Apply button
  5. Re-check both checkboxes
  6. Press OK

If you’re lucky, VS should be running smooth as butter again.

Photo by Morgennebel, cc-licensed.

moving the windows documents and settings profile folder

Connecting to the Interweb Tubes

If you’re running out of disk space on your C-drive on a Windows XP system (which other OS has a C-drive anyway?) you might be thinking of moving your C:\Documents and Settings\youruserprofile to another disk. In my case the profile folder was eating away a good 2.5 GB of space. Moving it saved my ass from having to constantly cleanup that drive and end up in trouble in the long run as slowly but surely updates would fill every last available bit anyway.

There’s a procedure from Microsoft that explains how to do this. In short it goes like this:

  1. Login as Admin
  2. Copy the desired profile folder to another drive, such as D:\Documents and Settings\Bob
  3. Start the registry editor (regedt32.exe) and change all references from the old path to the new one.

This last step is quite a job if you’ve been using the profile for a long time, like myself. I tried this on a test account first and I only had to replace a few references so I thought “Piece of cake! Let’s do this!”. Until I started the same thing for my actual profile and had to replace a gazillion references all over the registry. Bloody hell!

The annoying thing was that even after I replaced all references, some software was still referring to the old profile folder somehow. The bastards! My guess is that some software simply doesn’t expect you to move this folder and has a hard-coded reference built-in. However, there’s a solution for that as well. That solution is also a shortcut to avoid that tedious job of having to change all the registry values, which is bloody boring and prone to errors.

The fix is a tad of Unix magic that also exists for Windows NTFS drives, where you can create a link or virtual folder pointing to a physical folder on another drive. The official name is a “junction point”. For example you can have C:\Document and Settings\Bob point to D:\Documents and Settings\Bob, and not a single piece of software will notice that your files aren’t really on the C drive. Sounds pretty neat huh? This only works with NTFS drives, but any modern version of Windows uses that format by default so that shouldn’t be a problem.

So how do you go about this? Well, it goes like this:

  1. Log in as the administrator user (and not the one you want to move the profile for).
  2. Copy the profile folder to your preferred location on a drive with plenty of free space.
  3. Remove the source profile folder (or rename it, just to be safe).
  4. Create the junction point from the source folder, to the new destination folder, like so:
    linkd.exe "c:\documents and settings\bob" "d:\documents and settings\bob"
  5. Log back in with the moved user. You shouldn’t notice a single problem.

Want more info on that junction point magic? Check out how to create and manipulate NTFS junction points then.

Update: if you’re looking for a similar action on Windows 7 or Vista, check out the mklink command, which is basically the replacement for linkd for the newer Windows versions.

Photo by nickwheeleroz, cc-licensed.

the ultimate geek music player?

waveforms, precious little waveforms

I can’t believe it took me so long to find this gem but Foobar 2000 is the most geeky and cool media player by far. The name alone is good enough to get a geek to drool, download and check it out. What’s great even better is that its Open Source freeware, is hugely customizable when it comes to the user interface and is extendable using plugins. Geekisme indeed.

So why was I looking for a new tool to play some mp3’s with? Well I was getting tired of my trusty WinAmp really. WinAmp used to rock when it was doing exactly what it was made for. Playing mp3 or other music files in a minimalistic interface and having some kick-ass features I didn’t see in other players. Over the years however WinAmp started suffering from feature bloat as more functions where added like a CD ripper and burner, a video player and a ton of other stuff I never touched. I stopped updating at some point cause all the new stuff just slowed it down and I wasn’t using it anyway.

So when I started shopping around for something new and shiny to play my audio in I wanted it to support the following features at least:

  1. Be a damn good music player. Support for all well-known formats. You know, the basics.
  2. Have a media library, indexing all my mp3s and making it searchable. There too much stuff there to just pick & play.
  3. Look kinda nice. It’s 2010 after all.
  4. Send scrobbler data to Last.fm. Can’t let those awesome tracks go unnoticed now can we!
  5. Global hot-key support. I want to be able to stop/skip/pause a track using a global shortcut. No need to clicky-clicky around with the mouse, just hit CTRL-ALT-HOME and it’s paused. Geeky awesomeness.

Foobar2000 has em all, but you guessed that by now. You have to configure the global hot-keys yourself (Preferences > Display > Keyboard Shortcuts) so I copied the ones I’m used to from WinAmp. For the Last.fm support you need this plugin. The rest comes out of the box.

One really neat extra Foobar has is that the user interface is completely configurable (see these screenshots). You can pick & choose how you want it to look by selecting the UI components to display. Want the media library on the left? Add a graphical equalizer? Super minimalist look? Go ahead and tweak your ass off. There’s a number of preconfigured layouts but you can go ahead and start from scratch too. Wicked! It’s a hell of a time waster once you start messing with it too I’ve noticed. Hmm.

So if you’re looking for a good and lightweight media player, check out this Foobar 2000 thing and I bet you won’t be disappointed. It’s just a pitty it ain’t open sourced.

Photo by altemark, cc-licensed.

keeping state kicks ass

It does! What am I talking about? Anything that allows you to cut off a session you’re having, and restore it for later on, just like that. I’m talking that thing all laptops have, “hibernation mode”. The sweet part is that you don’t really have to own a laptop to enjoy the merits of hibernation. You can activate it on any XP system, with the same amount of spare drive space on the C drive as you have RAM in your machine.

I use it all the time really on my desktop PC’s. It speeds up the booting, or it gives me that impression, and I just leave apps open with stuff I’m working on. I do this at home, but mainly at work, where it’s really handy to get right back where you left off. Your cursor will even be blinking at the same spot you left it. Awesome.

Another way to keep state like this is when it’s built right into your software. Firefox does that nicely for example, by restoring all your open tabs from your last surfing session when you restart your browser. Not only is this super-handy when Firefox flakes out and dies on you (rarely, but still, it might happen), but it’s also handy when you stumble across this ├╝bercool site when you are late already for some social stuff and need to head out the door pronto. No need to save bookmarks or anything. Just exit, and go.

Keeping state. It rocks.

Photo by lecasio, cc-licensed

still a windows geek

Originally this post was called “I’m a Windows geek”, and was about how I installed Ubuntu after not being able to reinstall Windows XP because something was making the hardware detection lock up. Using Ubuntu I did manage to get through the hardware detection, and eventually diagnosed the problem to be able to reinstall the Redmond OS.

I spent a few days in Ubuntu back then, as it was the only running OS on my machine, and I thought that was a good time to find out if I could do everything I did on my Windows machine. At first I was impressed. Ubuntu installed without a glitch, basic software was installed and the UI was slick. Problem was I had to find replacement Linux tools for all the stuff I was used to in Windows and then I started noticing I’ve gotten quite used to the WinWorld apparently.

Little things ended up being very frustrating though. Shortcuts that work different in FireFox, mouse wheels that didn’t work at all… A lot didn’t feel intuitive coming from an MS system.

Eventually I managed to reinstall XP, and I totally gave up on the Ubuntu setup. A number of months ago I retried the Ubuntu path, upgraded it to the latest version and give it another shot. I Just noticed that it has been a few months again since I even booted it…

No matter how much Linux pwnz the Windows OS according to some, when you’re used to it, you kind of expect the same features. It sucks having to give up your favourite programs for alternatives that aren’t quite the same. Some of them are in essence equally good, but it doesn’t have to be that different to start sucking compared to what you’re used to.

WinAmp for instance totally rocks. I haven’t seen anything quite as good on Linux (or on Windows for that matter). Maybe I’m wrong though. I haven’t spent quite as much time searching for software tools on Linux than I have on Windows, I have to admit that. But luckily things are getting better at that front. Since I used a lot of FOSS software, and a lot of that is being ported over both platforms, I don’t have to stop using my beloved FireFox, GIMP, Open Office or VLC, which is great. So migrating is becoming a lot easier because of this, but not quite easy just yet.

One other huge frustration is that in Linux some things simply don’t work. ATI video cards anyone? Dual head displays? In fact, one of the differences between Windows and Linux in my eyes is this:

On Windows I’m surprised if a new piece of hardware I got doesn’t work.
On Linux I’m surprised (and happy) if it does.

I’ve gotten used to my OS to just work for me. I don’t feel like spending most of my time figuring out how to get something basic to work. It can be fun digging into configuration files and advanced settings if you have the time to do so, but in most cases I just want to run Setup.exe > Next > Next > Done and start using the damn app. By using Ubuntu I rediscovered how easy it can be to setup a Windows system.

So I guess I’m still a Windows geek for now.
Vista here I come? Oh crap…

Photo by Andrew Mason, cc-licensed

windows non-admin recap

You probably heard about that fact that running Windows with an administrator account isn’t a good idea, even though that is the default setting. I tried not doing that on my main machine, but it turned out to be quite a pain in the digital butt. After a few weeks of having to fast-switch to the admin user, or running some scripts to start a single┬á process as admin etc, I gave up, and switched back to the good old insecure admin mode.

I simply end up installing and uninstalling stuff all the time, being a geek and all. I also burn a CD now and then, and for some reason I also needed administrative rights for that. Some software also failed to work straight out of the box, which meant I had to figure out what the hell it was trying to access, and see if I could grant it enough permissions to get it to work anyway.

Now however, I’m using it again (non-admin mode that is) on an old laptop I have lying around. For that little machine it’s quite perfect, since I don’t change it’s configuration much, and it’s basically a simple surfing machine. I also removed the virus scanner from it (OMG!! I know. Living on the edge baby), so running as a non-admin is a much needed precaution in case I do manage to pull some nasty trojan off the web.

No problems so far actually. Non admin is sweet if you keep a few things in mind. Stuff like having to use the “Shared documents” folder to exchange files between user accounts. Limited rights block you from accessing files stored in Program Files for instance. That’s a good thing of course, but I’m just not used to that.

So I guess it all depends on how you are going to use your account/machine. Non-admin is workable for simple stuff. If you intend to change your configuration a lot, or start developing some software on it, non-admin is going to make that pretty damn annoying.

(Photo by jimmyroq, cc-licensed)