Windows’ find command

It would appear that, not-entirely-contrary to my common rant that Windows offers no text processing tools at all, Windows does offer a find command which is like a severely crippled grep.

It has five options:

U:\>find /?
Searches for a text string in a file or files.

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

  /V         Displays all lines NOT containing the specified string.
  /C         Displays only the count of lines containing the string.
  /N         Displays line numbers with the displayed lines.
  /I         Ignores the case of characters when searching for the string.
  /OFF[LINE] Do not skip files with offline attribute set.
  "string"   Specifies the text string to find.
             Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.

So it kind of does what I want about 70% of the time I use grep, and is probably a reasonable stand in afterwards. Certainly beats firing up notepad and ctrl-F ing.

Now to find an awk and a sed

UI Fail: scanpst.exe’s incompatibility

Sometimes, on trying to scan a PST with MS Office’s bundled scanpst.exe, you get the below error:

"An error has occurred which caused the scan to be stopped"

And a log that ends:

Fatal Error: 80040818

What MS meant to say was:

You’re scanning an Office 2003 PST file with the scanpst tool that shipped with Office 2007. For some reason, we decided that while Outlook 2007 can cope with both, scanpst can’t

In an attempt at usefulness:
On my WinXP/Office 2007 box, scanpst is at C:\Program Files (x86)\Microsoft Office\Office12\SCANPST.EXE and downloadable here.

On our Server03/Office03 box, it’s at C:\Program Files\Common Files\System\MSMAPI\1033\SCANPST.EXE1 and downloadable here.

I’ve no idea if these downloads are of any real use. Try them and see.

  1. I’m told the ‘1033’ pertains to geographic location, but I’ve no real idea. Browse if it’s not there. []

UI Fail: Windows XP ‘runas’ dialogue box

On right-clicking an executable1 in XP and choosing `Run As…’, you are presented with the below box.

How on earth is ‘Current user’ a reasonable default value? If I wanted to run it as me, I’d just double-click it…

  1. Though not every executable. If you want to run something in the control panel, probably the most common place to want to runas, you need to shift+right-click. Several MSI files don’t do it, and nor do any apparent CAB files. Let alone the inability to directly open a non-executable file as someone else. []

Moving WinXP’s My Documents

The My Documents directory location is stored in the registry at HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders in a key called personal.

The following script is what I use to remap this to u:/documents:

;; create some dirs:
mkdir documents
mkdir outlook

;; Move My Documents folder:
;; delete current setting
reg.exe delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Personal /f
;; create new setting
reg.exe Add  "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Personal /t REG_SZ /d u:/documents

Using Synergy to share a keyboard and mouse across PCs

Synergy is a really neat way of using multiple computers at the same time, like a more convenient KVM switch (you do need to be physically close to all of them).

It basically allows you to have a monitor for each PC on your desk, and one keyboard and mouse with which to monitor them. Switching between PCs involves just moving the mouse pointer onto the relevant screen. It uses ‘screens’ rather than monitors, so you don’t need to let it know if you’ve got a complicated multi-monitor setup on a host (or even if you add or remove monitors from one), and it allows for having screens of different sizes and for, say, the bottom half of one screen to line up with the top half of the next.

It’s a server/client model – you have one server box into which you plug the keyboard and mouse. The rest connect over the network to it (in cleartext, don’t do this where you don’t trust the network).

I have two hosts. My work laptop is running Windows XP and has an external monitor plugged in to it. My testing PC is running Debian testing and is a PC proper. Here’s my desk:
jup-linux2 is the left monitor (attached to the PC to its left, running Debian), jup-rmt07 is the laptop on the right, which is also attached to the Sony screen in the middle. Since I take the laptop home with me occasionally, jup-linux2 is configured as a server, jup-rmt07 as the client (less to unplug).

Synergy is in the debian repositories, so it’s just an apt-get install synergy. This provides two binaries, /usr/bin/synergyc and /usr/bin/synergys, which are the client and the server respectively.
To install it in Windows, you’ll want to grab it from their Sourceforge page

Configuring and starting the server
So, having installed, we can configure! The configuration file can be arbitrarily named, mine’s cunningly called ~/.synergy.conf and appears verbatim at the bottom of this. Synergy’s really rather configurable, but I’ve never found much need for more than the basics, so I’ve an incredibly simple setup.

First, we define some ‘screens’. Here we can also configure optons for screens, especially as regards the transference of caps-lock and num-lock statuses. I’ve no special requests, so I just list the hosts whose screens I want Synergy to manage:

section: screens

Second, we define the links. For each monitor, we state what is at any edge of it. This is used to decide where to put the mouse pointer on leaving the screen, so it needs to be done in both directions – the fact that jup-linux2 is to the left of jup-rmt07 does not imply to synergy that jup-rmt07 is to the right of jup-linux2:

section: links
	left = jup-linux2
	right = jup-rmt07

If I have two screens at different heights, I can tell synergy that the top 30% of jup-linux2 lines up with the bottom 40% of jup-rmt07, for example:

	right(70-100) = jup-linux2(0-40)
	left(0-40) = jup-rmt07(70-100)

Again, you always always always need to define the screen in both directions. The file is parsed by synergy to see what to do on leaving that particular screen – when you’re in jup-rmt07 and move towards the left of the screen, it’s only going to do anything if there’s a left defined for that screen, irrespective of how many rights point there.
If my screens are above and below each other, up and down are used. A screen can have as many other screens round it as you like, by assigning percentages of edges to different screens.

Configuring the server under Windows involves a different process to use the same principles. Essentially, you build the same text file as above, but in a clicky gui. It’s a little odd, but quite simple.

configuring Synergy server under Windows

To start the synergy server, we now run

synergys --config ~/.synergy.conf

Replacing ‘~/.synergy.conf’ with the path to wherever the config file is saved.

Configuring and starting the clients

So, we have a server. Now, clients.
On Windows, synergy is only one executable, so we start that, select the ‘Use another computer’s shared keyboard and mouse (client)’ option, stick the server’s hostname or IP in the box, and click ‘start’.
If you have a *nix client, the command to connect to a server at jup-rmt07 is synergyc jup-rmt07. synergyc provides a few options for changing the behaviour.

Starting Synergy automatically
Finally, I want them to start automagically on boot/login. For the linux host, this is relatively easy, add the following to your crontab:

@reboot synergys --config ~/.synergy.conf

And it’ll be started on boot.
To start it under Windows, click the ‘AutoStart’ button. This will let you configure it to start it on login or, if you have the requisite permissions, start on boot.

Cheating at LDAP in MS Active Directory

adsiedit.exe allows you to click your way through the AD directory tree and view and edit attributes, in short. It’s pretty handy for quickly getting the dn of an object when you’re not entirely sure of the directory structure to begin with. It’s all rather self-explanatory and clicky friendly:


sudo for windows. Sort-of

Windows (XP) has a pretty basic users system, and switching between users is pretty convoluted. Also, msi binaries don’t have the Run As... option in their right click menu by default. There’re two ways of doing it:

First, the runas command, which is sort-of sudo for Win32. There’s no /etc/sudoers, it uses the AD/NTFS ACLs. Really, it’s su -c Usage:

runas /user: 

Both should be in quotemarks if there are spaces, username should specify domain. For example, my favourite is:

runas /noprofile /user:"avi [email protected]" cmd

Which skips loading my profile (think sudo -m), and opens up a dos prompt with my rights. It opens a command window to enter your password, there is no way of supplying it with the command.

The above generally works, but a more persistent method is to start your own shell.
<ctrl><alt><del> to bring up the task manager, kill explorer.exe, click New Task..., browse to c:/windows/ and find explorer.exe. Right-click, choose Run As... and enter the admin credentials.