2007-11-30

Xandros and Firefox on Radio National

It was so weird driving to work and hearing a segment about Xandros and Firefox on Radio National (MP3 recording). For a few minutes, I thought I had passed into some bizarro open-source world because the presenters hardly mentioned Microsoft Windows.

2008-06-21: Updated MP3 link.

2007-11-28

Unexpected Windows Scheduled Task Copy-Paste Bug

I never expected to find this bug. In Windows XP, if you try to copy and paste a task in the Scheduled Task folder, you may get this error message: Cannot copy <Task Name>: The source and destination file names are the same. Even the obvious workaround doesn't work: copy a task, rename the original and paste the new task. unlike Windows Explorer, Scheduled Task doesn't seem to give a copied task a name such as Copy of x.

2007-11-25

Beginning PowerShell

Introduction

Microsoft's PowerShell is a scripting environment based on the .Net framework. PowerShell is aimed at replacing Windows Cmd and Windows Scripting Host (WSH) for administrative tasks. What interests me is that I can use .Net objects interactively and in a script, without having to write and compile a program. As I explore PowerShell, I'll write about features that I find interesting and useful.

In this first article, I describe really basic use of the PowerShell console. I assume you downloaded and installed Powershell.

Help!

Powershell installation provides a lot of on-line help. You obtain information using the get-help cmdlet (essentially a built-in command). There's so much information that the trick is to figure out the appropriate help topic:

> help # or 'get-help'
< 299 lines … >
> help about_Arithmetic_Operators
TOPIC
    Arithmetic operators

SHORT DESCRIPTION
    Operators that can be used in the Windows PowerShell to perform
    mathematical operations
…

You can also download the on-line help as a CHM file (search for "Windows PowerShell Graphical Help File").

Interactive Mode

You can enter commands for processing immediately:

> 'abc' + 'def' # String concatenation
abcdef
> 5+6 # Addition
11
> 5*6 # Multiplication
30
> 30%7 # Remainder
2

The '#' marks the start of a comment. All text from '#' to the end of the line is a comment.

Using .Net Classes and Objects

How long is a string (said with a straight face)? Since we are using .Net String objects, each string should have a Length property:

> 'abc'.Length
3
> 'def'.Length
3
> ('abc' + 'def').Length
6

You can find the methods of an object using get-member.

> 'abc' | get-member


   TypeName: System.String

Name             MemberType            Definition
----             ----------            ----------
…
get_Length       Method                System.Int32 get_Length()
…

What's 2 to the power of 8? The .Net System.Math class defines a set of common mathematical functions. Again, you can use the get-member cmdlet to find out what functions are available in any class, but this time, with the -static option because the class, not individual objects, define these functions.

> [math] | get-member -static


   TypeName: System.Math

Name            MemberType Definition
----            ---------- ----------
…
Pow             Method     static System.Double Pow(Double x, Double y)
…
> [math]::Pow(2,8)
256

The System.Math is pre-loaded by PowerShell and can be accessed as [System.Math], [Math] or [math]. Square brackets refer to .Net classes and some aliases have been defined for these classes.

How do you know whether an object or a class has the required function? No easy answer: trial-and-error, and experience with other class libraries.

Tab Expansion and Aliases

It's pretty tedious typing a full cmdlet string, so there are two shortcuts available: tab expansion and aliases.

If you enter get-m<TAB>, you should see Get-Member. For some reason, you have to enter the name of cmdlet up to the '-' (dash) character before tab expansion works.

The get-member cmdlet also aliased as gm. What aliases are available? Use the get-alias cmdlet, which is also aliased as gal, for a list of available aliases.

> Get-Alias

CommandType     Name                                                Definition
-----------     ----                                                ----------
Alias           gal                                                 Get-Alias
…
Alias           gm                                                  Get-Member
…

Conclusion

At this point, you can run some simple commands using PowerShell and know how to find some on-line information.

2007-11-13

Uninstall Product Desktop Shortcut

During the development and test phase of a project, I have to install and uninstall daily program builds for testing, so I'm pretty interested in reducing the amount of time and effort required to uninstall programs. Here's how my uninstallation process evolved:

In the beginning, use Start / Control Panel / Add or Remove Programs.

Spend less time by starting Windows' Add or Remove Programs dialog using the Run dialog by typing Windows+R appwiz.cpl.

Then you might notice that the Windows XP Add or Remove Programs dialog takes up to 30 seconds to start and there's no quick way to find the desired program. It's annoying that the list of programs doesn't scroll when you hit the PageDown and PageUp keys or when you type the first few letters of a program name. (The Vista equivalent, Programs and Features, doesn't have these limitations.)

Finally, using Windows Installer, msiexec, you could uninstall any program if you have the ProductCode. Just create a desktop shortcut with the following string in the Target field:

C:\WINDOWS\system32\msiexec.exe /uninstall <ProductCode>

P.S. You can find the ProductCode of your program using this script.

2007-11-12

Weird NLS_LANG JDBC Connection Error

A colleague got a new computer and when he tried to connect to an Oracle server with a JDBC client, he got this error:

ORA-12705: Cannot access NLS data files or invalid environment specified

After comparing our Java environments, he found that he had user.country = BZ (BZ is the top level domain for Belize). He changed his Regional and Language Options to English (Australia) and then he had no problems connecting to the Oracle server.

I think when JDBC client tries to connect to the Oracle server, the client specifies its locale and when the Oracle server fails to find the required locale files, the server throws the ORA-12705 error message.

2007-11-11

Event 1530, User Profile Service

After having to debug a couple of Windows profile problems recently, I started to keep an eye for Warning or Error events in the Windows Event Viewer. The latest warning was Event 1530, User Profile Service, where there was some conflict between processes writing to the registry as I was logging out and had the following details:

 2 user registry handles leaked from ...:
Process 932 (\Device\HarddiskVolume2\Windows\System32\svchost.exe) has opened key ...
Process 3472 (\Device\HarddiskVolume2\Windows\System32\IFXSPMGT.exe) has opened key ...

Process 3472 is IFXSPMGT.exe (Infineon Security Platform Software) but what was process 932? One solution was to run tasklist and save the list of process numbers in the current session. Here's the command to run:

tasklist /svc /fo table /fi "imagename eq svchost.exe" > C:\Temp\Processes.txt

Very roughly, we are looking for all services started by svchost.exe.

I ran the tasklist command in the previous session and found that process 932 was WinDefend (Windows Defender, Microsoft's anti-spyware program).

14-Nov-2007. For Windows pre-Vista, if you receive Event ID 1517, Microsoft provides User Profile Hive Update (UPHClean.exe) utility to detect and free the registry. There isn't a version of UPHClean.exe for Vista yet.

2007-11-08

Very Slow FTP Download Fixed

When I download files from our FTP server using my notebook on the company LAN, the download speed was 10 to 20 kbits/sec, which is very slow compared to using a local desktop, where the download speed was closer to 150 kbits/sec. There was no problem downloading files from external Internet sites. The IT guy and I puzzled over this problem off and on; it was annoying but not critical. I tried different FTP clients but there was no difference. Then the IT guy suggested turning off Deterministic Network Enhancer (DNE) (open Local Area Connection Properties and clear the DNE's checkbox). When I restarted my FTP client, the download speed improved to the same level as the desktop.

It turns out that DNE was installed with the VPN software on my notebook. I have to remember to re-enable the DNE when I use the VPN. Still beats me why it only affected FTP downloads from our local server.

14-Nov-2007. It's not DNE. When I reset the network adapter after I start the FTP client, the download speed improved. IT Guy thinks my notebook may require an updated network adapter driver or BIOS.

Updated my Asus BIOS from 214 to 218 and the networking problem seems to be fixed.

15-Nov-2007. It's not the BIOS either. Updated my Realtek RTL8160/8111 network adaptor driver from 5.666.301.2007 to 5.680.1023.2007 and I'll see what happens the next time I restart my notebook.

16-Nov-2007. Success! My notebook download speed went past 130 kbits/sec on the first go.

2007-11-06

Firefox more popular than MSIE6

I can't quite believe my eyes. W3Schools Browser Statistics page shows that in September 2007, there more hits from developers with Firefox than MSIE6 or MSIE7 (35.4% vs. 34.9% vs. 20.8%). In CY2007, MSIE7's take-up rate started high but has since slowed to the same rate as Firefox, indicating that all early adopters have upgraded from MSIE6 to MSIE7. As the year progressed, MSIE6's share fell, and developers migrated to MSIE7 and Firefox in equal proportions. MSIE7 is built into, or auto upgraded in, new Windows distributions, so the fact that developers go out of their way to install Firefox must indicate a higher perceived value in Firefox over MSIE7.

Its also nice for Firefox to segue from a niche technophile browser into mainstream awareness. For instance, in a recent game show on telly, Are you smarter than a 5th grader?, both Firefox and MSIE are mentioned in the same breath:

Q: What type of software are Firefox and Internet Explorer? (That's roughly the question.)

A: Web browsers.