Tuesday, September 29, 2009

Windows Vista Secret #1: Open Command Prompt Here

I don't know about your workflow as a developer, but I often find myself switching back and forward between an Explorer window and the command shell. For example, sometimes I'm looking around the filesystem for a project that I created a while back and then I want to build it from the command line or rename some of the files or something.

Here's a trick that I don't think many people are aware of. Right-click on any folder on your Windows Vista machine while holding down the shift key. You'll see an extra context-sensitive menu item there: Open Command Prompt here. Just click on this menu and a command window will open with the current working directory set to the folder's actual location.


Figure: folder context-sensitive menu, with and without the shift key modifier.

In the past there was a Windows XP powertoy that did this; now it's built into the operating system (albeit hidden away to protect the unwary from themselves). What's really cool about this is that if the target folder is a network location, Windows Vista silently maps a network drive to that location before opening the folder (so that your command prompt has a valid path containing a drive letter) and then deletes the network drive once the command prompt is closed.

Windows Vista Secret #2: Copy as Path

Ever wanted to copy a link from a network file share into an email, and wound up having to traverse the path, click on the address bar, copy the details out, paste it in and then type the filename itself (with the appropriate quotation marks?

With Windows Vista, there's an easier way. In the same hidden context-sensitive menu I mentioned in the first secret, there's another helpful shortcut: Copy as Path. Unlike the command prompt trick, this menu item appears both for files and folders, so you can use this anywhere you want to quickly grab a shortcut to send someone else.

Windows Vista Secret #3: Bringing Back Start / Run

The Start menu got a big overhaul in Windows Vista, with a number of significant changes made as a result of usability testing and research. One of the nicest innovations to my mind is the search bar at the bottom, which searches through your programs, document files, emails and anything else for which a search provider is registered; this saves a lot of time hunting around. Want to run Powerpoint without having to browse around the "All Programs" menu? Just type "Powerpoint" in the searchbar. Can't remember which of the myriad dialog boxes and settings you have to go through to find the Device Manager? Just type "device" in the search bar.

Of course, there are times when you may still just want the fast but dumb Run dialog that Windows XP provided:

It seems that some people think we got rid of this altogether, when in fact we just removed it from the default settings since most people won't need it any longer. The quick way to get at it is to use the Win+R shortcut key combination at any time - this is what I tend to use most of the time.

If you want to restore it permanently to your Start menu, here's what you do:

  1. Right-click on the Start menu and choose Properties;
  2. Select the Start Menu tab and click on the Customize... button;
  3. Ensure the "Run command" option is checked.

Now the Start / Run command will be restored to its full glory. Of course, you can swap in and out a bunch of other choices (I like the Administrative Tools to be right there, but I don't much care for Pictures, Games and Music to be top-level items on my work machine.) Here's how I have my default menu configured - you'll see it's also docked to the left-hand side of the screen:

Windows Vista Secret #4: Disabling UAC

If you're a reader of this blog, I'm going to take a low-risk gamble and assert that you probably consider yourself a power user. You pride yourself in the responsibility of having full and absolute control over your machine environment and anything that comes between that perfect human-machine symbiosis is to be spurned. If only there were a way to turn User Account Control off on a Windows Vista machine, you'd upgrade immediately. Well, dear reader, I'm here to help.

Firstly, it's worth a brief digression into the benefits of this feature. Running as admin is a bad thing, as most of us know. Aaron Margosis has blogged extensively on this issue, and I won't rehash it here. But for reasons of compatibility, running as a standard user can still be a somewhat painful proposition. Windows Vista attempts to give you the benefits of both worlds by allowing administrators to execute most processes in the context of a standard user and only elevating the privileges on their user token by consent, in addition to allowing standard user accounts to perform administrative tasks by selectively elevating a process to use administrator-level credentials.

In general, UAC has turned out pretty well. It was pretty intrusive in early builds, prompting often and sometimes capturing focus at the wrong time. For the vast majority of users, UAC will offer a valuable level of security protection that will protect against malware: it simply won't have the rights to perform invasive actions like installing device drivers or services. Once a system is configured, you'll rarely see UAC prompts unless you're an inveterate settings tweaker. Incidentally, you can find out a great deal more about how UAC works, what you need to do to your own applications so that they co-operate well with UAC, and the rationale for its design at the official UAC blog.

It is possible to switch UAC off. I really don't recommend it - if you like full control over your machine, surely you want to know when something is attempting to perform an administrative-level action? Nevertheless, I'd prefer to have you run Windows Vista without UAC than having you run a different operating system.

There are two ways to disable UAC. The easy solution is through Control Panel. Type "UAC" into the search bar at the top of the screen and you'll see this task presented:

This approach is pretty brute-force, though. It just switches the whole thing off. There's a more subtle configuration choice that gives you some of the benefits of UAC without any of the prompting. You'll need to edit the local security policy to control this, as follows:

  1. From the Start search bar, type "Local Security Policy"
  2. Accept the elevation prompt
  3. From the snap-in, select Security Settings -> Local Policy -> Security Options
  4. Scroll down to the bottom, where you'll find nine different group policy settings for granular configuration of UAC.

Perhaps the best choice to select is to change the setting:
User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode
from Prompt for consent to Elevate without prompting.

What does this do? Despite the warning from the Windows Security Center, UAC isn't actually switched off. It's still there, and all your processes will still run as a standard user. To prove this, open a command prompt and try to save a file to the c:\ directory. You'll get an access denied error message. However, when a process is marked for elevation, instead of getting the secure desktop elevation prompt, the request will be silently approved. To show this in action, right click on a command prompt shortcut and choose "Run as Administrator". You'll see the command prompt open without elevation, but the window title will show that you're running with full administrative privileges.

Using this approach is better than nothing, but it's a bit like relying on everyone else having a vaccination against measles to protect yourself from infection. Read the explanations on the second page of the property sheet for each policy setting before tinkering, and be careful!

Saturday, September 19, 2009

Windows Vista Secret #5: Running Quick Launch Items

Saw this posted on one of the internal forums today, and I thought this was something that was worth sharing. If you're a keyboard junkie, you'll love this.

Do you have a few applications that you're always firing up? Would you like a system-wide keyboard shortcut to run them? Here's what you do. Simply add shortcuts to the Quick Launch toolbar, as shown in the screenshot below.

Now you can simply use Win+1, Win+2, Win+3 and so on to launch each application. For example, on my machine, Win+3 launches Notepad and Win+6 launches the VS command prompt. This works no matter what application has the focus.

More coolness coming your way soon, courtesy of Windows Vista!

Windows Vista Secret #6: Running a Command Prompt During Setup

If you're doing a fresh install of Windows Vista, you'll probably use a bootable DVD so that you're able to reformat the system partition. But sometimes you might find yourself in a situation where you could really use a command prompt as you go through those initial configuration stages (for example, when I installed Windows Vista on my home media center machine I needed to run the diskpart command line utility to convert a dynamic disk back to a basic disk structure).

Here's the magic key sequence: simply press Shift+F10, and you'll be presented with a command prompt. This also works after Windows Vista has rebooted for the first time on an upgrade, although be very careful what you do here - there's almost no good reasons to be interacting with the system at this point in time, and you shouldn't expect us to get you out of any holes you dig yourself into if you start making invasive changes at this point in time.

Windows Vista Secret #7: The Oldest Component in Windows?

We go to fairly extreme lengths to try to maintain compatibility with older applications, as Raymond Chen's blog often demonstrates in vivid fashion. As an example of this, some of you may remember seeing Jim Allchin's demonstration of Visicalc (the earliest spreadsheet) at PDC 2003 running on Windows Vista (then known as "Longhorn", of course).

So I wondered - what is the oldest component still present in Windows Vista? After a bit of digging around, I think I've finally discovered the answer.

Dear old edlin, the very first line editor in MS-DOS, is still available for your batch editing pleasure over a quarter of a century after its introduction. According to wikipedia, edlin even pre-dates MS-DOS, having been written for an even earlier operating system that was one of the company's first acquisitions. My first exposure to MS-DOS was version 3.2 on my father's office computer, and I used to remember most of the mnemonic commands by heart. It's not a user-friendly tool, but it was fast to load and more forgiving of mistakes than the alternative of copy con filename.txt.

This is one secret that has mere curiosity value, but I still have a warm spot for this venerable editor and I salute its indefatigability!