Category Archives: windows

how to get code from tfs from the command line

cmd.exe

Ever wanted to pull an update from the TFS server for all workspaces you have without having to start up the Visual Studio? Well I did. Visual Studio is rather slow in starting up and then you have to navigate to the TFS explorer (clicky clicky) and manually update the workspaces (clicky clicky) and then wait till the whole thing is done and VS becomes responsive again (waity waity).

You have the tf.exe command which you can use from a command prompt, but that requires you to use the VS command line because the right paths are set there. You could set the paths so they are available in all your shells, but that’s not very handy either.

I just wanted a batch script that I could run from any shell, that would just update my workspaces for me. Nice and easy.
Like when I press CTRL-R in Windows (Run) and type getfoo.cmd<enter>, it just makes it all happen for me.

So here’s how I did that:

@echo off

cls

:: Importing VS 2012 command line variables so we can run TF.exe
if exist "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat" (
echo Importing VS 2012 environment variables...
setlocal
call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat"
)

echo.
echo *** Updating TFS workspaces ***
echo.

:: Repeat this for all workspaces you want to update.
d:
cd D:\WS\pathtosolutionfiles\

tf get . /version:T /recursive

echo.
echo *** Workspace updated. ***
echo.

windows rescue kit on a usb stick

Attempt Repair Install

While cleaning up an old machine I was first using CCleaner from Windows to wipe some partitions because DBAN crashed for some reason on it. To clean some of the Linux partitions on the drive which Windows can’t access, I dropped them so I could re-add them as NTFS partitions for further wiping. Problem was I forgot those partitions where also hosting my master boot record, so when I rebooted to confirm my partition changes… I ended up with a unbootable system.

Oops.

Now I had to find a way to wipe those disks from Linux, but first I still wanted to get access to my WinXP setup. I could have just nuked it from orbit (read: boot from a Linux Live CD and shred it) but I was just wondering if I would manage to get it to boot again, just in case I do this on a system that really matters some day. So I started browsing to the ISO’s available on the Universal USB Boot installer and ran into the awesome Trinity Rescue Kit.

I installed it on a very small USB drive (265MB) I had lying around and managed to rewrite me a Windows boot record with the tools supplied from the text-based menu. Nice! I also noticed that it has a bunch of disk rescue tools on board like a backup tool, full NTFS support, the Midnight Commander explorer for file recovery and a Windows password reset tool (hackedy-hack). On top of that it also has a virus scanner on board, ways to set up network file shares and good, detailed documentation.

This distro is certainly one that is getting a nice spot on my PC CPR tool belt. Without exploring all the goodness Trinity has to offer I’m sure it’s a huge time saver if you need to help out with a unbootable system or one seriously infected with trojans or virii. You can even use this to set up a headless file share server in no time if you want.

Good stuff.

Photo by lilbambi01, cc-licensed.

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.