NSIS File command not working after calling SetOutPath

I wrote a NSIS script which copies two MSI files to $INSTDIR\Installers directory and then execute them, it’s pretty easy and following is the code

Unfortunately above code will not work and it’s saying NSIS cannot find these two msi files, but I’m sure they existed!

Then I tried to put $INSTDIR at beginning of the path

Now a MSI Help Dialog pops up with information about how to use msiexec command.. Apparently it failed again.


To solve this issue, we need call SetOutPath before ExecWait, like following

The first three lines will copy SqlLocalDB.msi and OutsideX64.msi files to $INSTDIR\Installers, and the last three lines will install MSI files at $INSTDIR\Installers.

It’s because that ExecWait (Exec, ExecShell) command will use $OUTDIR as working directory, and this path can be set by SetOutPath command (By default $OUTDIR is set to $INSTDIR).

If we don’t call SetOutPath command explicitly before ExecWait, its working directory will be $INSTDIR\Installers, and it will try to install MSI files under $INSTDIR\Installers\Installers directory, which is apparently wrong.


(And this guy had same problem as well http://stackoverflow.com/questions/17105455/install-sql-server-2008-r2-express-sp2-with-nsis)

Outside In Viewer Quiet Install not working

I need to install Outside In Viewer component silently in my NSIS installer. The Outside In Viewer installer is a MSI file, to install it silently, we need run following command in command line.

msiexec /i OutsideX64.msi /q

Above command will finish immediately, but it’s finished so soon that I think the installation is likely failed.

Since the command line didn’t return anything, I need enable logging to check what’s wrong with it

msiexec /i OutsideX64.msi /q /log log.txt

(Note that the log.txt file should be created in advance, otherwise an error message will show.)

In the log file we see such message

MSI (s) (C4:BC) [14:54:57:760]: Product: OutsideX64 — Error 1303. The installer has insufficient privileges to access this directory: C:\Program Files\OIX. The installation cannot continue. Log on as administrator or contact your system administrator.

By reading this log message, we know we need run this installer as administrator


To request Administrator privilege, add following line into our NSIS installer (at first line)


MinGW unable to find pkg-config

Recently I need build libewf on Windows, and MinGW is chosen as the compilation tool.

Open MSYS and run autogen.sh in libewf source directory, then following error is appeared

unable to find: pkg-config


I read source code of autogen.sh and realized that it’s trying to locate pkg-config at /mingw/bin directory,  Then I checked MinGW installation directory and bin folder, found there is no such pkg-config file. So we need install pkg-config manually.


Install pkg-config

At MinGW Wiki page it introduces two methods to install pkg-config, but using a pre-compiled version is much easier. Here is pre-compiled pkg-config download address from SourceForge. After downloading is completed, extract pkg-config.exe and move it to MinGW/bin directory, retry running autogen.sh we will found this problem is solved

WPF Set StartupUri in code


StartupUri is a property of Application class, which sets the first UI to show when application starts. By default it’s set in App.xaml file, e.g.

In above code the StartupUri value is MainWindow.xaml, and using default value is OK for most of times.


Why Set StartupUri in Code?

But what if you want to show other windows according to different conditions? Assume our application can open .proj files, so the file name will be passed in as command line arguments.  Now we want to show a file chooser dialog at startup if user run our application directly (without double clicking .proj files), and open another window (call it Project Explorer) when user start application by double clicking .proj file.

In this case we need to check command line arguments, then set corresponding StartupUri in code.


How to Do it

First in App.xaml.cs, add an override method OnStartup for Application class.

This method will be called at startup of application.

Setting StartupUri in OnStartup method is just a recommended way, you can set it in constructor as well. The execution order is: Constructor -> XAML Parsing -> OnStartup, so setting StartupUri in constructor will be overridden by XAML and OnStartup, and StartupUri in XAML will be overriden by OnStartup


Next we set the StartupUri according to whether filename is passed in.

In above code we call System.Environment.GetCommandLineArgs method to get command line arguments. You can see the StartupUri is actually an Uri object, its UriKind is UriKind.Relative. (If we don’t specify the UriKind parameter, we will get an UriFormatException)



Apache Derby Database Browser


Apache Derby is an embed database implemented in pure Java. It’s implemented in pure Java, thus it’s more compatible with Java.

There are mainly three database browsers for Derby

Since the first two softwares are commercial, in this tutorial we will introduce how to use SQuirreL.



  • JRE (or JDK)

Download JRE (or JDK) from java.com and install it. Don’t forget to add its bin path to environment variable.

  • SQuirreL

Download SQuirreL from installation page and install it using following command

java -jar squirrel-sql-<version>-install.jar

(or you can double click the jar file if you’re under Windows)

  • Derby Client and Derby Embedded Driver jar files

Download the zip file from this link, then extract derby.jar and derbyclient.jar from the zip file. Next copy these two files into SQuirreL’s lib folder.

If the two jar files are copied to correct path, you will see in SQuirreL’s Drivers panel Apache Derby Client and Apache Derby Embedded are enabled.

SQuirreL Drivers Panel

SQuirreL Drivers Panel



Create a connection to Derby database

In Alias Panel, click Add Alias button

SQuirrel add alias

SQuirrel add alias

The Name field is not important, and you can fill in with anything. In URL field you enter the server address and database name, e.g. jdbc:derby://localhost/derby_test


And if you want to connect to embedded file database,  you need set JDBC Connection URL like following:


Assume the database is located at D:\derby_test, then the JDBC URL should be


SQuirreL add embed derby database

SQuirreL add embed derby database



C# Int (Integer) Infinity


I’m implement a data structure which is used to convert a time range to human-readable text, e.g. 0-7 days to “Within 1 Week”, 7-30 days to “1 Week to 1 Month”. Here I use Tuple<int,int> to represent the time range but not two integers, because we can define a Dictionary<Tuple<int, int>, String> to represent a map from time range to text.

But how could we represent “Over 2 Weeks”? Apparently the second parameter of the Tuple should be infinity.


To represent infinity for an integer, we can use int.MaxValue (it’s actually Int32.MaxValue)

So we can solve above problem using following code



Why Convert JAR to .NET DLL

Imagine your company builds an online file converter, and its backend programming language is Java because of its position in web development. And in this project you build a file parsing library (jar format certainly) which is used to parse different types of files.

After this project is done, your boss decides to create a Windows desktop version for this software. Now the best choice is .NET, but how can you reuse your java parsing library? That’s why IKVM.NET existed.

IKVM.NET Introduction

IKVM.NET is a .NET implementation of Java which allows us to run Java code in .NET (C#, VB.NET, etc.) easily. It includes following three components:

  • JVM in .NET (which means you can run java byte code in .NET)
  • Java class library implementation
  • A compiler converting java byte code to .NET IL

There are many famous Java projects converted to .NET using IKVM.NET already, such as Tika, Curator, etc. Even Mono has include it as a built-in component.

Start Converting

This will generate a DLL file named libpst.dll from libpst.jar in current directory.

Without -target:library option, it will generate an exe file.


WPF Dragablz Tutorial Part 2: Set Custom Tab Host Window


Dragablz is a WPF Tab Control which can let us to drag and drop tabs, drag tabs out as floating window and docking support, etc. It’s a pretty good control, but its documentation is too few.

In Dragablz’s official tutorial, we use default InterTabController for TabablzControl, and InterTabClient property is not specified for InterTabController, so tearing a tab out directly will only create a window which is same as the container window of the TabItem.

In this tutorial I will show you how to create a custom Tab Host Window.


Step 1 – Implement IInterTabClient

To set a custom Tab Host window, we should implement the IInterTabClient interface, which contains two method signature

Only the first method GetNewHost will be used here, so we can ignore the TabEmptiedHandler method.

Create a new class named MainInterTabClient.cs and make it implement IInterTabClient interface, then modify the GetNewHost method like following

The return value is the new host for dragged out tab, next we will create a new window for it.


Step 2 – Create a new Tab Host Window

Add a new window named TabHostWindow

Visual Studio add new window

Visual Studio add new window

In XAML View, add following code


Step 3 – Add Window into InterTabClient

Go back to MainInterTabClient.cs, update the GetNewHost method

It will create an instance of our newly created TabHostWindow as the host of dragged out TabItem.

Step 4 – Create a ViewModel for MainWindow

Next we need create a ViewModel class to bind newly created InterTabClient, name this class MainWindowViewModel.


Step 5 – Bind ViewModel

Now we need bind the ViewModel we created just now, add following line into your MainWindow constructor:

Then modify XAML of your MainWindow


Finally, we finish it! Drag a tab out you will see the tab will be inside a new clean window.

WPF ModernUI Tutorial Part 1


ModernUI is a nice WPF theme and a styling framework which let you build a modern, beautiful application easily. Are you poor in designing skill and have problem with designing GUI for your WPF applicaiotn? If so, you have to try ModernUI, it is the best choice for you. In web design, there is Bootstrap for building great UI. And for WPF, it is Modern UI.





The installation is really easy, just search “ModernUI” in Manage NuGet Package Window, and select “ModernUI for WPF” item and click “Install”

Install ModernUI for WPF in NuGet Package Manager

Install ModernUI for WPF in NuGet Package Manager

Or run following command in Package Manager Console

 Install-Package ModernUI.WPF


Create a ModernUI Window

First create a new WPF Application Project named “ModernUISample”. After creating project, select MainWindow.xaml, change the XAML as following:

The ModernWindow class is defined under FirstFloor.ModernUI.Windows.Controls, so add following line to MainWindow.xaml.cs to import this namespace

Then let MainWindow inherit from class ModernWindow


Click “Debug” button to run the program, we will see a black rectangle with a light blue border is shown. What’s wrong with it? It’s because that we have not applied the theme files to our application.

Open App.xaml, and add following code:



Run the program again, you will see a modern window is shown

Modern UI blank window

MySQL Auto Backup

First create a shell script which is used to backup database, here we named the script as mysql_backup.sh:

In above command, we use date command to generate current date, and use it as part of filename.

After that we need to make this file executable


To make this backup script run automatically, we should create a cronjob. Type following command to open cronjob editor

crontab -e

Write following text and save it

Above command means the cronjob will run at 0:00 everyday