Martin's technology blog – 10 latest posts
Blog content
Active categories:
- Vista (10)
- Office 2007 (1)
- Logitech (1)
- Darwin at work (1)
- Blog (1)
By date:
- This month (1)
Blog calendar
| Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|
| << Jul | Sep >> | |||||
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
2008-08-05 | Quoting strings in INF AddReg sections
The syntax of the INF files controlling Windows driver installation can be a little tricky at times. In this particular case I was trying to add a registry key whose value contains some quoted paths. It took me several attempts to get it right and the help on INF strings sections was also rather cryptic and not very helpful with its lack of examples.
I wanted to create a key with the following value (of course the actual example was slightly different but this will do to illustrate the problem):
"C:\Program Files\MyTool\Run.exe" -datadir"C:\Program Files\MyTool\data\" -debug -title"MyTool" -verbose
Here's the solution (or should I say: the closest I got):
[MyTool.Addreg]
HKLM,Software\Me\MyTool,Command,0x00000000,"""C:\Program Files\MyTool\Run.exe""" -debug -datadir"""C:\Program Files\MyTool\data\""" -title"""MyTool""" -verbose""
The documentation states:
[...] any string [...] that is itself a quoted string, must be enclosed in a pair of double quotation marks characters [...]
The INF parser not only discards the outermost pair of enclosing double quotation marks for any "quoted string" in this section, but also condenses each subsequent sequential pair of double quotation marks into a single double quotation marks character. That is, """some string""" also becomes "some string" when it has been parsed.
The second paragraph is slightly beyond my understanding, in particular considering some of my intermediary test results that you can find at the bottom.
The first paragraph at least explains the double quotes at the end. Inside the string all quotes also need to be tripled.
The beginning of the remains somewhat of a mystery to me. The triple quote at the beginning of the string is converted into a single quote in the registry.
To make matters worse, Microsoft's own ChkInf, which comes with the DDK, doesn't like any of the working solutions. It doesn't accept any less than four quotes at the end of the string. However, with more than two quotes at the end of the string, the resulting registry ends up containing a trailing quote. Anything with two or fewer (one and zero also work but at least seem syntactically incorrect to me) works fine with regard to the end result.
As I promised, here are some of my intermediary results. The slightly simplified AddReg commands and the corresponding result behind the semicolon:
HKLM,,TestA,0x00000000,"""Some string""" ; "Some string" HKLM,,TestB,0x00000000,""Some ""quoted"" string"" ; Some string HKLM,,TestC,0x00000000,""Some "quoted" string"" ; Some string HKLM,,TestD,0x00000000,""Some \"quoted\" string"" ; Some \quoted\ string HKLM,,TestE,0x00000000,""Some """quoted""" string"" ; Some "quoted" string
Is anyone wondering why Microsoft didn't just adopt the syntax of one of the many programming languages out there where similar problems are unheard of? The developers could have just copied the code from MSVC (or any of the other hundreds of MS implementations of the same algorithm) and users wouldn't have to even read the documentation. But heaven forbid a win-win situation!
2008-07-10 | OS detection in a Windows shell script
There seem to be many ways to detect the Windows version (e.g. XP vs. Vista) from a batch file, some of them fairly complicated. It's not exactly as easy as it should be because there's no decent environment variable and the output of ver is difficult to parse.
However, I found the following to work just fine:
: OS detection
for /f "tokens=3" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentVersion') do (
set WindowsVersion=%%i
)
if "%WindowsVersion%"=="5.1" set IsWindowsXP=1
if "%WindowsVersion%"=="6.0" set IsWindowsVista=1
: Show some debug information
echo Windows version: %WindowsVersion%
if defined IsWindowsXP echo IsWindowsXP = true
if defined IsWindowsVista echo IsWindowsVista = true
2008-05-19 | Integrating Flex and Bison into Visual Studio
There's a pretty good tutorial from Microsoft (what do you know, they <em>do</em> like open source ;-) about how to integrate Flex and Bison into Visual Studio:
Understanding Custom Build Rules in Visual C++ 2005: Building Flex and Bison Files from the IDE
Unfortunately I ran into a problem after integrating it into my project. Flex kept crashing with the following output:
1>------ Build started: Project: MyProject, Configuration: Debug Win32 ------
1>Generating lexical analyser...
1>flex: fatal internal error, exec failed
1>Project : error PRJ0002 : Error result 1 returned from 'C:\WINDOWS\system32\cmd.exe'.
1>Build log was saved at "file://C:\MyProject\Debug\BuildLog.htm"
1>MyProject - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Some experiments showed that Flex was unable to find M4 (i.e. m4.exe) and then crashed with the above not-so-helpful error message.
The workaround is easy: Make sure that either m4.exe is in the path or set the M4 environment variable. Since I use a somewhat special directory structure for Flex, Bison, and some other tools I already had a wrapper script in place, so integration was easy:
: Wrapper script for Flex : : This script sets some environment variables that are required for Flex to : find all its libraries and helper files/tools.
@echo off
: Determine the path of the wrapper script set GNU_PATH=%~d0%~ps0
: Set PATH for cygwin1.dll and M4 for the M4 tool itself. : If we don't define M4 Flex fails with the following error message: : "flex: fatal internal error, exec failed" set PATH=%GNU_PATH%\lib;%PATH% set M4=%GNU_PATH%\bin\m4.exe
: Launch the real Flex executable with the same arguments %GNU_PATH%\bin\flex.exe %*
In case you're wondering, the directory structure I'm using looks something like this:
%GNU_PATH%
¦ bison.cmd
¦ flex.cmd
¦
+---bin
¦ bison.exe
¦ flex.exe
¦ m4.exe
¦
+---lib
¦ cygwin1.dll
¦
+---share
+---bison
¦
+---m4sugar
m4sugar.m4
You can see the two wrapper scripts at the top level.
For completeness' sake the wrapper script for Bison, which defines one additional variable, so that Bison can find its M4 helper files:
: Wrapper script for Bison : : This script sets some environment variables that are required for Bison to : find all its libraries and helper files/tools.
@echo off
: Determine the path of the wrapper script set GNU_PATH=%~d0%~ps0
: Set PATH for cygwin1.dll, BISON_PKGDATADIR for the M4 meta files : and M4 for the M4 tool itself. set PATH=%GNU_PATH%\lib;%PATH% set BISON_PKGDATADIR=%GNU_PATH%\share\bison set M4=%GNU_PATH%\bin\m4.exe
: Launch the real Bison executable with the same arguments %GNU_PATH%\bin\bison.exe %*
By the wy, if you use Lex in your Visual Studio project, you may also want to check out this article which documents a bug in Microsoft's original FlexBison.rules file.
2007-11-21 | The little window that couldn't
Not only is the new user interface in Office 2007 one of the biggest usability steps backwards I've ever seen in a Microsoft program, the implementation of the new look seems to have a few interesting "features" like this one:

That's right. This is my Excel window the way it shows up about 70% of the times I launch it. The "feature" auto-enabled itself a few weeks ago and hasn't gone away since. The only solution? Restart Excel a few times and trust the law of probability--praised be my beloved keyboard shortcuts.
2007-11-06 | The most basic computer skill
Creating a community website is not only quite satisfying because you get to see how customers actually use your products, sometimes it's also quite funny. A few weeks ago Logitech launched the QuickCam Team website which targets developers and users of webcams on alternative platforms and just by looking at it it should be pretty obvious that we don't do product support. (And if it's not obvious enough there's a big fat note on the contact page.) Nevertheless, some people try their luck by reporting random, completely unrelated issues that are poorly phrased and impossible to understand. Here's a funny example:
Subject: Logitech QuickCam 4000
Can you please give me detailed instructions on how to make it impossible for anyone to change my password or otherwise get around it? This is urgent. Thank you.
Somewhat confused by the subject I assumed that the person was referring to her newly created account for the QuickCam Team forums:
I neither understand the subject of your e-mail nor the idea behind your request. What are you trying to achieve? What do you mean by "get around it"?
And once again, the response was no less confusing than the original e-mail:
I created a password for access to the camera images. Now the password box will not recognize my password.
This problem is preventing me from shutting down the computer. I cannot close the image studio, nor shut down the computer.
How can I permanently erase the password?
Part of me wants to help a confused user but a much bigger part of me wants to actually see the live stream from her webcam showing her sitting in front of her computer that apparently doesn't shut down because she forgot the password to a long obsolete piece of software. Not because I like seeing desperate users or because I hate technically challenged people, but because people need to learn to read. If your butcher has a sign outside that says "I don't bake bread" you don't go inside and ask for croissants. Using a computer is not like watching TV. It needs many skills, and reading is the most important one.
2007-11-02 | Not enough space or not enough brain?
Read carefully and think about it for a while:

There are so many aspects of this dialog box that I don't understand, it's not even funny. How about freeing up some space by uninstalling the very cause of this dialog box?
2007-08-15 | California Spam Building
Unbelievable to what trouble certain companies go to improve their search engine ranking. I just received the following two comments to some fairly old articles: (Click the picture to see the corresponding article--obviously I have removed the spam comments.)
Clearly this is a real person and not just a script because the text--sort of--makes sense and because my blog has a pretty nifty anti spam option that hasn't failed a single time so far.
Is it really worth the money? It looks like it took him more than 10 minutes to write two comments. Does the guy do this in his own time? Does he have any friends at all? And has he ever heard of the rel="nofollow" attribute that most search engines respect? (Whether that tag really has helped reduce blog comment spam is a whole other story.)
If you care to see some more examples (without a doubt in the next few days more results will show up), search Google for «blog comment "California Team Building"».
That being said, I really appreciate true comments to my articles, so don't hold them back on purpose. ;-)
2007-07-26 | MSN viruses
In the last two days I've received viruses over MSN messenger on two different occasions. Both times, they seemed to come from friends of mine. The first one was in the form of the following message and came with a simple link:
Vote for me: http://22460.vasedrunjinsaterfuns.com/2215/67179/
At the time of this writing the link above still works and downloads a file called vote.zip. The file is not actually a ZIP archive, instead it's a simple Windows executable. Now, I don't know how people are supposed to be tricked into executing it, because simply double clicking it obviously won't do any damage, but maybe something to do with MSN users' habits of renaming .exe to .zip before sending them?
A scan of the file with the pretty good multi-engine scanner over at Virus Total found a Stration worm, which originated as an e-mail worm and is now apparently broadening it's infection horizon.
The second one was a little trickier, it actually managed to infect my boss and a co-worker of mine from whom I then received the following message, immediately followed by an incoming file request for images.zip:
Sup, seen the pictures from the other night?
A few things were obviously suspicious here:
- My friend just doesn't talk like that. As a matter of fact, few people use uppercase in IM nowadays and I think the last time somebody used "Sup" was last decade. (I may be wrong on the latter one though ...)
- The file was called images.zip yet contained only a single file. Nobody zips a single image because they can't be compressed anyway, and especially not one of some 40 kB.
- The "image" that was contained was called IMG34814.pif, with an extension that is more than suspicious, but might slip the eye of someone who hasn't been suspicious up until now.
I can hardly blame the average Joe for becoming infected with the second one, so the blame goes--*fanfare*--to Microsoft for two reasons.
Apparently, the current version of Windows Messenger is scriptable to an extent that is so obviously dangerous that I can't believe the functionality is still in there.
Despite Microsoft proclaiming Vista to be the most secure Windows ever, .pif files are still executed without warning.
The second point is especially grave for a number of reasons. Because of the nature of the PIF file format it does not contain any executable code but only meta information, so it could be easily be checked for authenticity. What's worse is that extremely few people have used .pif files ("program information files") after Windows 3.1, so either displaying a very obvious warning message or dropping the registration of the .pif extension altogether would not disrupt anyone.
If you want to disable .pif files on your system, you can use the following registry change to do so (or download this .reg file and double click it):
HKEY_CLASSES_ROOT\.pif\(Default) = "piffile_disabled"
2007-07-25 | Windows Messenger sucks
To be more precise, it doesn't suck everything. It just sucks certain messages into digital nirvana, notably the ones with links in them.
At some point in the last one or two days my MSN messenger started rejecting or simply eating messages when I sent out links to my friends. Sometimes I would get timeouts, sometimes it looked like the message was sent successfully but the recipient never got it.
Of course, at first I blamed my messenger software because I'm using the generally great Miranda instead of the highly annoying and way too colorful and animated Microsoft client. But a quick test showed that the messages get lost even with the official client.
I'm assuming it's either an anti-virus feature that Microsoft enabled (just yesterday I got a message from a friend--that he never sent--saying "vote for me" and containing a link that wanted me to download some file) or just an accidental feature that Microsoft enabled (a bug in marketing speech). If it's the first one, someone really didn't think very far, and if it's the second one, then I'm just baffled.
Either way, it strengthens my opinion that ICQ is just the better network. They've had some issues as well, especially with login stability, but messages are transmitted a lot more reliably. Obviously that doesn't help me because the rest of the world uses MSN. Yet another proof that the better product doesn't always win.
2007-07-24 | Windows Vista (Part 5: Power management)
Announcing a new operating system as the "Best choice for laptops" is a pretty confident step given the last years of laptop history. I have seen few combinations of laptops and operating systems that worked properly in all situations, but I have seen many cases where mobility was greatly reduced due to bugs in the power management implementation. Especially with new systems the situation is usually a lot less stable than with older operating systems. Did Microsoft manage a surprising turnaround?
I tested Vista's power management thoroughly on my laptop and ran a quick test on my desktop machine. Here is my experience report.
Lenovo ThinkPad T60
Exactly because power management is such a difficult and hardware dependent topic let me state for the record that I'm using an up-to-date Lenovo ThinkPad T60. Some of the described issues may be and probably are at least partly due to Lenovo bugs. Nevertheless it will be interesting to see all the regressions since XP, which ran, slept, and resumed quite well on my machine.
Stand-by: One of the first things I noticed after installing Vista was the extended stand-by mode. No, I'm not talking about the new hybrid sleep mode, but about something that I call coma sleeping mode: hit the stand-by button and your computer sleeps--with a 1:4 chance for good. In some cases the only chance of getting it back to life is pressing the power button for a few seconds or removing the battery pack.
Another feature that I've come to like is the so-called backpack heater mode. It works like this: You're at the office, it's 7pm. You decide to go home and grab some dinner on the way, so you put your computer to sleep. You stuff it in your backpack and get going. Later that night (usually when you get home), you start unpacking your backpack and discover that it's quite warm. What happened? After a certain (random?) amount of time, Windows decided to wake up and hung during the attempt. Not only is this sudden wakeup a great idea when you're biking home and your laptop gets shaken around, it's also nice to discover that your battery is suddenly empty.
No updating of BIOS and drivers or changing of settings seemed to help make suspend mode anything close to usable. Don't get me wrong, though. Some things work, just not stand-by.
Hibernate: Hibernate is very reliable on my machine. It takes ages (maybe one minute) to actually write the entire state to the hard disk, but at least I lose no data. And the first phase of the wake-up, i.e. reading back the state from the disk, is quite fast. The second phase of the wake-up is not as convincing, though. It easily takes another 30 seconds to unlock the screen and often the fingerprint reader doesn't react at the first time.
Ironically, hibernate has become a little faster when I upgraded my RAM from 1 GB to 2 GB--a highly necessary step. There's more to write to the hard drive but the unlocking seems to go a little faster.
Unlock: Not strictly part of power management, it is still closely related because the computer is locked after resume from stand-by or hibernate. For example when you go on your lunch break, do you suspend your computer or do you just lock the screen? Hibernate is pretty much out of question and with a broken stand-by mode there's not much choice left. So you hit Win+L and leave your desk. So far so good.
The annoyance starts when you get back from your break. On Windows XP it was easy: Enter the password and start working. Occasionally, there were a few seconds delay caused by hard disk activity, but in general it was fine. Windows Vista doesn't just lock the screen; it suspends the current user session and displays the "Switch user" screen. With my initial 1 GB of RAM Vista would take up to a minute (!) to recover from a locked screen. The hard disk was going crazy and even the mouse wouldn't respond. Got back from your break? Go take another one.
Who's to blame for this? A new technology called SuperFetch. (You can read some interesting things about SuperFetch in an article called Why Does Vista Use All My Memory?.) I find the following excerpt from a Microsoft feature highlight very ironic:
"In previous versions of Windows, system responsiveness could be uneven. You may have experienced sluggish behaviour after booting your machine, after performing a fast user switch, or even after lunch."
If anything, SuperFetch made this effect worse on Vista! If you have 2 GB of RAM it's a little less severe but I'd take the old XP behavior back any day. This incredible delay is also great for security. I routinely used to lock my computer when I would go away from my desk, just because it's good practice. Since I installed Vista I simply stopped doing that, I just don't want to wait that long when I get back. The "Most secure Windows ever"? You be the judge.
USB and stand-by: When I was still trying to get the stand-by mode running I noticed some interesting behavior with USB devices. Unplugging the mouse after suspending the laptop just woke up the system again. And at least once my mouse didn't work anymore after the system resumed from stand-by. I had to unplug it and plug it again.
Screen blanking: Vista blacks out the screen after the computer has been idly running on battery for a while. Previous versions used to do that too, so nothing special about this. What's really annoying about it on my computer is that every time I touch a key and the screen comes back, the screen brightness drops to some medium default level and I have to turn up the brightness again to see something.
Desktop machine
The other day I installed Vista on a desktop PC that is maybe two years old, just to see how Vista performs on a desktop. So far it looks quite okay, but power management looks similarly broken.
When I send the computer into stand-by or hibernate mode, it seems to work, but as soon as the suspending process is complete, the system wakes up again, without any keyboard or mouse interaction at all.
A little bit of searching the web turned up a lot of other people who have similar problems and one resolution that seems to help for some of them: Uncheck the "Allow this device to wake the computer" box for certain devices (network adapter, keyboard, mouse) in the device manager.
In my case I needed to uncheck the function for both the HID Keyboard Device (a Microsoft Natural Ergonomic Keyboard 4000) and the HID-compliant mouse (a Logitech MX900 Bluetooth mouse).
Of course, this "fix" effectively ruins the comfort of being able to wake your computer without reaching the power switch under the table. Even installing the latest drivers from Microsoft and Logitech didn't help.
Bottom line
The rule that the latest operating system is the worst in terms of power management stands strong. While Microsoft had some innovative ideas (i.e. the hybrid sleep mode), the current state of power management in Vista is worse than XP in every respect.
I sincerely hope that the first service pack will take care of this, and that hardware manufacturers keep fixing the bugs on their side. It would be a shame if laptop users would have to wait for a second service pack to make the most basic and most required power management features usable.
Until then it's hibernating, waiting, and the occasional cursing at a computer that refuses to wake up from its nap.
For reference, here's a list of links to the other parts of my Vista review:

