Wednesday, February 26, 2014

Updates? What updates?

I’m experimenting with running our standard desktop Windows 7 image as a Hyper-V guest on my laptop. The laptop has Windows 8.1 installed. This means I can do the day-to-day stuff on Windows 8.1 and just switch to the VM when I need to check the experience for the users. There’s no good reason for me to be stuck on old technology just because our environment is always way behind, especially when there’s so much goodness in Windows 8!

It went pretty smoothly. Even though the laptop host OS isn’t a member of the corporate domain it lets the traffic through OK so the guest can join the domain. I had to ask the infrastructure team to update the network switch to allow the additional MAC address. Seems like an outdated security solution, especially given that MAC address spoofing is so easy, but whatever.

The image itself then network installed into the VM (I think we use SCCM for the network installs). The image includes Office 2013 and some other bits and bobs, so after a while I’m good to go.

However, the network icon in the notification tray indicates I have no internet connection, even though I do, and can Google quite happily.

I didn’t expect this to be a problem, but it actually is as some Office stuff, such as OneNote, will not open your SkyDrive notes. Instead we get some twee message about helping me get online. Outlook won’t open SharePoint tasks from their notification emails either.

Initially I thought this might be because IPv6 is on by default, and I know our infrastructure isn’t happy with that, so I disable that on the Hyper-V virtual switch. Still no joy.

Then I wondered if it was because I left my WiFi on the host as well as the plugging in the network cable, but disabling that didn’t fix it either.

Some Googling gets me to a suggestion that this might happen because of outdated network drivers, but this is a guest VM so uses the Hyper-V drivers from Microsoft. Automatic Updates are switched on so we should be up to date.

But I forgot about the “context”. I’m using someone else’s infrastructure, and in this case it’s configured to get updates locally, but never actually gets any updates. I forget what the backstory here is. I’ve a funny feeling they had WSUS installed at some point, but then abandoned it. I manually kick off the update process and tell it to ask Microsoft. 70 important updates are ready for me to download. It does most of these, then stops for a reboot.

When it comes back, sure enough, the VM now detects its internet connection correctly.

UPDATED: Boo. Following an overnight shutdown and restart the VM is back to “no internet connection” again.

Mouseless Admin

Here’s some simple tips for driving Windows 8 from the command line, instead of the mouse.

Just search for it

Windows 7 has a built in search engine running by default. This can index your documents and emails and also Windows applications and utilities. You can usually find what you need by simply typing a keyword.

Pressing the Windows key or Start button will pop up menu with a box to type into. Windows 8 is similar: the Windows key (and Start button which was reintroduced for Windows 8.1) will open the Start screen. If you start typing it will automatically open the Search charm.

Command line

The traditional command line is still available. You can press Windows Key + R to open the Run dialog. Enter a command and hit Enter to execute it. This is great for simple single commands: see list below. If you want more interaction then you can use the Run dialog to open a command window by entering cmd, or a PowerShell window with powershell.

cmd Open a command window
powershell Open a powershell window
shutdown /s Shuts the computer down
shutdown /r Reboot
shutdown /l Logoff or signout
c:\ Opens a Windows Explorer window to the root of the C drive, for example. Works with any path.
%UserProfile% Opens a Windows Explorer window to your personal files


Most commands will take switches. In the list above I showed 3 switches that can be given to the shutdown command.

Most commands will take the /? switch which makes the command display some help. You’ll need to be in a command window to see the output.

Environment variables

The %UserProfile% command actually resolves an environment variable. In this case the variable, called UserProfile, contains the path to your personal file store area. When the Run dialog is given a path it opens it with Windows Explorer.

You can see the full list of environment variable by using the set command, but you’ll need to be in an interactive window to see the output.

Interactive commands

Here are some more commands, but these all require some interactivity to be useful.

set Displays current environment variables. Can also change them.
exit Quits the command line session and closes the window.
whoami Displays your username. Useful for verification when having permissions problems.


PowerShell is the command line’s big brother. You almost certainly want to use this in preference to the command line.


Many administrative tasks require administrator rights, which are not available by default due to the User Account Control (UAC) security feature which was introduced in Windows Vista. You almost always want to leave UAC on. To do anything that requires administrator privileges simply elevate your PowerShell window, for example.

First launch a PowerShell window as described above. This won’t be elevated by default.

Now use that PowerShell to launch an elevated PowerShell:

Start-Process PowerShell –Verb RunAs

This will open another PowerShell window, this time with admin rights. Note the title of the window starts with Administrator: to indicate this.


You can save yourself a few keystrokes by using start instead of Start-Process. start is a PowerShell alias that simply maps back to the Start-Process commandlet.

You can use Start-Process to launch other applications, for example, and even URLs, which will open in your default browser:

Start-Process “”

File paths will open Windows Explorer and we can use built-in environment variables to refer to our home folder, for example:

Start-Process c:\users
Start-Process $home

You can use get-variable to list all the current environment variables.

You can also use Start-Process to switch to another account, which is useful if you typically run as a normal user, but have a special high-rights account for doing some tasks.

Start-Process PowerShell –Credential domain\hi-rights-user
Start-Process dsac

The first command launches PowerShell as another user. It will popup a window to ask for your password then open another PowerShell window. Use that for the second command, which launches the Active Directory Administrative Centre, for example and assuming you have it installed: search for Remote Server Admin Tools (RSAT) to get it.

Tuesday, February 25, 2014

Mouseless Hyper-V VM stuff

Here is a brief collection of stuff I found useful when switching from using mouse to keyboard for launching virtual machines.

This is all on Windows 8.1, but some or all may work on earlier versions.

You can list the virtual machines using get-vm. This will produce a list which includes the VM names.

You can then use the names to start and stop the VMs using start-vm and stop-vm. They both take the VM name as the first parameter and support wildcards. stop-vm shuts down the image by default, but you can use -Save or –TurnOff switches: use get-help stop-vm for more details.

I usually use Remote Desktop to interact with VMs. You can launch this by calling the client application. The following command line will connect in full screen. Use mstsc /? to get more help.

mstsc /v:machinename /f

You can break out of the VM session by pressing Ctrl+Alt+Home. The screen may seem the same, but the focus is now back with the local host machine, not the virtual machine, so your key presses are passed to the host. You can now Alt+Tab through the other applications running on the host, including other Remote Desktop sessions, so you can use this to switch between sessions.

Monday, February 3, 2014

WIX – writing Windows installers

I’ve finally got around to looking into WIX: Windows Installer XML. WIX lets us declare the operations we need to install some software, such as creating folders & copying files, and then generates an MSI file. The Windows Installer uses that to install, uninstall & repair the installation.

You can get the toolset from the project’s website. It’s open source so nothing to pay.

There’s also a tutorial on the website, but I highly recommend buying the book (WIX: A Developer’s Guide to Windows Installer XML, linked from the site). It’s comprehensive and written in a tutorial style: you’ll have a basic installer working after chapter 1, the it leads you through various common installer tasks in a logical order, introducing concepts and detail as required.

I’ve only used it for basic file deployment and installing a Windows Service, but the book covers XML configuration files; creating web sites in IIS; creating databases and running SQL to create tables. All the fiddly stuff I never quite seem to get around to automating.