14 December 2011

Outlook Locks Newly Created Folder / Directory

When saving an attachment in Outlook 2007, you can create a new folder in your filesystem first. However, Outlook locks that folder, so you can't move or rename it. You can unlock that folder by ...

  • Saving the attachment in another folder.
  • Creating another folder (though not a sub-folder of the one you just created).
  • Restarting Outlook.

There's an extra method listed in Folder or drive lock after saving attachment or message: use drag-and-drop.

05 December 2011

Google ChromeFrame incompatible with Oracle Hyperion DRM

If you have installed the Google ChromeFrame add-on for Internet Explorer (MSIE) 7 or 8, you may find that you cannot login to Oracle Hyperion Data Relationship Management (DRM) 11.1.2.1. After MSIE loads the DRM login page, you may see some Javascript errors and when you press the Log on button, nothing happens.

Coincidentally, I started seeing this error message on another web site: ERROR: Possible problem with your *.gwt.xml module file. The compile time user.agent value(ie8) does not match the runtime user.agent value (safari). Expect errors. It seems that Google ChromeFrame add-on, which I installed to improve Javascript performance when I was using IE7, can send the wrong user-agent information to a server (even if the add-on is disabled). I have since upgraded to MSIE8, which is fast enough, so I no longer needed ChromeFrame and I uninstalled it.

Now, I can login to DRM and the GWT error messages no longer appear.

02 December 2011

Specify Rows or Columns for Excel AutoFit

If you use the Excel AutoFit Method to resize cells to display their contents nicely, remember to specify whether to AutoFit rows or columns in Excel, i.e. use Range().Columns.AutoFit or Range().Rows.AutoFit, not just Range().AutoFit. If you don't specify rows or columns, Excel produces Run-time error '1004': AutoFit method of Range class failed.

26 November 2011

Minimal JavaBean introspection example

Just playing with JavaBeans, so here's a small example to create a simple JavaBean, set a property and read it.

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class SimpleBean {

  private final String name = "SimpleBean";
  private int size;
  public int getSize() {
    return size;
  }
  public void setSize(int size) {
    this.size = size;
  }
  public String getName() {
    return name;
  }
  
  public static void main(String[] args) throws IntrospectionException {
    SimpleBean sb = new SimpleBean();
    sb.setSize(59);
    BeanInfo bi = Introspector.getBeanInfo(sb.getClass());
    for (PropertyDescriptor pd : bi.getPropertyDescriptors()) {
      testGetValue(sb, pd);
    }
  }
  
  public static void testGetValue(Object sb, PropertyDescriptor pd) {
    System.out.print(pd.getName() + "=");
    Method getter = pd.getReadMethod();
    Object arg1[] = {};
    try {
      Object value = getter.invoke(sb, arg1);
      System.out.println(value);
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }
  }
}

The output of the program is:

class=class SimpleBean
name=SimpleBean
size=59

11 November 2011

Grep -f: No blank lines

If you search for a list of patterns in a data file using grep like below, don't include a blank line in the pattern file otherwise grep prints the entire data file.

grep -f patterns.txt data.txt

It's as if you had typed:

grep "" data.txt

See GNU Grep Manual

18 September 2011

Create an MSIE Favorite using VBA & WSH

A little sub-routine to create MSIE Favorites for MS-Office users. It uses Windows Scripting Host (WSH) which has a shell object that has functions to find a computer's Favorites folder (SpecialFolders()) and create a URL shortcut (CreateShortcut()).


Option Explicit

'Add references:
'1. Microsoft Scripting Runtime (Scripting namespace)
'2. Windows Script Host Object Model (IWshRuntimeLibrary namespace)

Public Sub CreateFavorite(ByVal strName As String, ByVal strUrl As String)
  Dim fso As Scripting.FileSystemObject
  Set fso = CreateObject("Scripting.FileSystemObject")
  
  Dim wshShell As IWshRuntimeLibrary.wshShell
  Set wshShell = CreateObject("Wscript.Shell")
  
  Dim strFavorites As String
  strFavorites = wshShell.SpecialFolders("Favorites")
  
  Dim shortcut As IWshRuntimeLibrary.WshURLShortcut
  Set shortcut = wshShell.CreateShortcut(fso.BuildPath(strFavorites, strName & ".url"))
  shortcut.TargetPath = strUrl
  shortcut.Save
  
  Set shortcut = Nothing
  Set wshShell = Nothing
  Set fso = Nothing
End Sub

Note to myself: don't confuse:


  • IWshRuntimeLibrary.WshShell with Shell32.Shell in Microsoft Shell Controls and Automation
  • WshShell.SpecialFolders() with FileSystemObject.GetSpecialFolders() function. The latter function only returns a small number of special folders (windows, system and temporary).

29 May 2011

Avoid multiple instances of a task in Windows Task Scheduler

Using Task Scheduler, one way to run a task more often than once a day was to repeat the task within the day. For instance, if you wanted to run a task every hour, you would repeat the task once an hour for that day. Now, if the task's running time is longer (e.g. the task is delayed by a slow network connection) than the repeat interval then another instance would be started even if you specify Do not start a new instance!

For a backup task, my workaround is to specify an hourly repeat interval and call a wrapper (e.g. a CMD or VBS script) to test for a lock file before executing the main program. In the wrapper, if the lock file exists then the wrapper aborts else it creates a lock file, runs the main program then deletes the lock file.

It looks like a task's Do not start a new instance parameter only applies to triggers. With Task Scheduler 2.0 (Vista onwards), you can create triggers for specific times of the day (say 01:00, 02:00, etc. for hourly triggers) and only one instance of a task is started. It's a pity there aren't shorter trigger intervals because to schedule a task every hour of the day, you have to create 24 triggers.

16 April 2011

Running Batch Files in Vim Ex-Mode

To modify a file using vim in ex-mode, you should be able to do this: vim -esn < modify.ex File.txt. The -esn option starts vim in ex-mode, a non-interactive session and no backup is created. The modify.ex file can contain a sequence of editing commands, ending with wq to write and close the file. However, in a Windows cmd session, the editing commands in modify.ex are executed but vim doesn't exit.

My workaround is to run a command (-c option) which uses vim's source command to run modify.ex: vim -esn -c "source modify.ex" File.txt.

26 March 2011

Configure NetBeans to Statically Link MinGW C & C++ Libraries

Installed MinGW g++ 4.5.2 and got the following Windows error when trying to run a C++ program I just compiled: The program can't start because libgcc_s_dw2-1.dll is missing from your computer. After fixing that error, Windows displayed a similar message regarding libstdc++-6.dll. Basically, g++ doesn not statically link the C and C++ standard libraries with an executable by default.

  • In Windows, copy the required library files, libgcc_s_dw2-1.dll and libstdc++-6.dll from the MinGW bin folder into the same folder as the executable or add the MinGW bin folder into the PATH environment variable.
  • If using NetBeans 6.9, configure the project properties to statically link the libraries to the executable:
    1. Select menu item File, Project Properties.
    2. In the Project Properties dialog, expand node Build, Linker.
    3. In Command Line, set Additional Options = -static-libgcc -static-libstdc++

05 March 2011

Leading Semicolon Comments a Line in CMD FOR /F

I wondered why the following CMD script was not processing some lines ...

for /f %a in (test.txt) do @echo %a

... with this sort of test where the semicolon is a field separator. All the lines were processed when the field separator is a space, tab or comma.

x;y;z
;y;z

When I ran the script, the echo command is only called for the first line. It turns out that, by default, for /f regards any line starting with a semicolon to be a comment and ignores it. It's similar to using:

for /f "eol=;" %a in (test.txt) do @echo %a

Note that the Microsoft documentation doesn't state the default for the eol keyword.

See Also

12 February 2011

Negate Numbers as String in Gawk

I had to negate numbers in a data file. My initial script simply negated the required field. Here a test:

gawk "{ print -$1 }"
123
-123
123.45678
-123.457

I wanted to preserve all the digits after the decimal point so I tried printf() (the multiple double-quotes is to escape double-quotes in Windows CMD):

gawk "{ printf("""%10lf\n""", -$1) }"
123
-123.000000
123.45678
-123.456780
123.456
-123.456000

Hm, now the result was being padded to the right depending on the number of digits specified. Since I only wanted to negate the values and not do any arithmetic, a trick is to add or delete the leading minus sign from the input string depending whether the input value was positive or negative, respectively:

gawk "{ print $1<0 ? substr($1, 2) : """-""" $1 }"
123
-123
123.45678
-123.45678
-123
123
-123.45678
123.45678

01 January 2011

NTFS Compression versus Compressed (zipped) Folders

A New Year posting!

While playing with WMI to compress folders, I realised that NTFS compression is different from ZIP files. At the start, I wondered why my script didn't seem to create any ZIP files even though the call to SWbemObjectEx.Compress procedure was successful. Turns out that my test folder was being compressed in NTFS but I wasn't looking for it correctly; in Explorer, the folder's name is displayed in a blue colour and its Size on disk is smaller than its Size but its icon and type is the same as a regular folder. On the other hand, Compressed (zipped) folders which are just files that have been compressed, have a zipper and padlock icon. A great way to publicise a fundamental file system feature, eh?

References