Detection of Executing Program in Inno Setup

Illustration

When upgrading your application it is very good practice to let your setup program know whether your application is running. This way setup will tell you to close your application instead of requiring Windows restart.

Solution comes in form of Mutex synchronization primitive. Application will create it and hold it until it is closed. If setup notices that application already has mutex under control, it will “complain” to user. It is then user’s task to close application. It is not as comfortable as closing application automatically but it does the job.

Since we need a global mutex for this purpose, we should not use something that could get used in other application for other purpose. To me best format of name is MyCompany_MyApplication. It is highly improbable that anybody else would use it. If you want to be (almost) sure getting random string is also a possibility.

For this to work we need to tell InnoSetup which mutex we plan on holding:

[Setup]
...
AppMutex=Global\MyCompany_MyApplication
...

In application we need to use same Mutex name:

namespace MyNamespace {
    internal static class App {
        private static readonly Mutex SetupMutex = new Mutex(false, @"Global\MyCompany_MyApplication");

        [STAThread]
        internal static void Main() {
            //do some great stuff.

            Application.Run(new MainForm());

            SetupMutex.Close(); //notice that it HAS to be after Application.Run
        }
}

P.S. Why do we MUST put SetupMutex.Close() after Application.Run() is exercise left to user. I will just note that it has something to do with garbage collection.

P.P.S. While this was written with InnoSetup in mind it is also applicable to virtually all setup systems out there.

Thanks Microsoft

Illustration

I reinstalled my machine and I had to install some of my tools. To keep things simple, I just went to download them from my own site. I was somewhat surprised at a warning: “vhdattach201.exe is not commonly downloaded and it could harm your computer”. I made this program but now even I wasn’t sure whether something has gone wrong.

So I checked everything. And yes, there is nothing wrong with my programs. It is just that some fool in Microsoft decided that what we need is another warning.

I cannot even start to comprehend what this will solve. If utility with couple of thousand downloads triggers this behavior so will lot of other people’s programs. Users will see this warning couple time through day. And they will ignore it. What IE 9 brought us is just another dialog that we will not read.

Connecting Windows 7 to Old Samba Software

Illustration

I got myself one simple (maybe too simple) NAS: IcyBox’s NAS902. It’s purpose was mostly just handling backups so lack of features didn’t bother me.

What did bother me was accessing this box from Windows 7. When I used NAS’ guest account only, everything was fine. When I added new SMB account with my user name and password I could not access it anymore. To make long story short, issue here was in ancient version of SMB server inside NAS902. It supported only NTLMv1 as authentication protocol. Windows 7 do not use that protocol (and for a good reason) by default. My computer and my NAS just weren’t speaking same language.

Solution was simple enough. First I had to start “Local Security Policy” (in Windows 7 it is as easy as writing exactly that in search box). From there I had to go to “Local Policies” and then “Security Options”. From list of policies I found “Network security: LAN Manager authentication level”. Changing setting to “Send LM & NTLM responses” solved issue.

P.S. Yes, I know, this lowered security in my network considerably. I need to find another NAS as a long-term solution.

Installing Fresh Windows 7 on Mirrored Volume

Illustration

I am fan of software mirroring in Windows 7. Yes, I know, hardware RAID is better, faster, more reliable etc. However, it has one big disadvantage. It is notoriously difficult beast to find. All those RAID controllers integrated on motherboards are usually just software RAID with some hardware support. And their drivers are notoriously bad.

Usually we first install Windows 7 on standard MBR partition. Only after setup is done we can convert disk to dynamic one. After that mirror can be added. Well there is a little bit better way of doing things.

First you need to go into dark dungeons of command line interface. Just boot Windows setup as usually and press Shift+F10 on first screen. This will just open command prompt in which you just write “DISKPART”. That utility will be your host for the day.

Now you need to create some dynamic disks. CLEAN command is there to ensure that you start with blank drives and same procedure needs to be done for both disks. If you are not certain which disks are in computer, you might want to execute “LIST DISK” first - just to get numbers right:

SELECT DISK 0
 Disk 0 is now the selected disk.

CLEAN
 DiskPart succeeded in cleaning the disk.

CONVERT DYNAMIC
 DiskPart successfully converted the selected disk to dynamic format.

SELECT DISK 1
 Disk 1 is now the selected disk.

CLEAN
 DiskPart succeeded in cleaning the disk.

 CONVERT DYNAMIC
DiskPart successfully converted the selected disk to dynamic format.

After this you’ve got two dynamic drives that need to go into some form of RAID. I opted here for RAID 1 (mirroring) but you could also select RAID 0, RAID 5 and a simple volume:

CREATE VOLUME MIRROR DISK=0,1
 DiskPart successfully created the volume.

Volume isn’t worth anything without it being formatted. Next step is just that. Do notice that I call this volume by number 1. On my system volume 0 is CD-ROM and newly created volume got next number. If your system has additional disks (or preexisting volumes), you can check which volume you need with “LIST VOLUME” command:

SELECT VOLUME 1
 Volume 1 is the selected volume.

FORMAT QUICK
   100 percent completed
 DiskPart successfully formatted the volume.

In order to boot from this volume you need to give it a partition:

RETAIN
 The selected volume now has a partition associated with it.

Of course, given partition needs to be activated. Here you will start counting from number 2 since partition 1 is reserved for “system stuff”. If you are not sure, quick check with “LIST PARTITION” is recommended:

SELECT DISK 1
 Disk 0 is now the selected disk.

SELECT PARTITION 2
 Partition 2 is now the selected partition.

ACTIVE
 DiskPart marked the current partition as active.

SELECT DISK 0
 Disk 0 is now the selected disk.

SELECT PARTITION 2
 Partition 2 is now the selected partition.

ACTIVE
 DiskPart marked the current partition as active.

With this done you can type exit twice (once to exit DISKPART and once to exit command prompt) and do installation as you normally would. Only other thing worth mentioning might be slight confusion regarding two separate drives where you can install Windows. Everything will work no matter which disk you select there.

And this was all. As soon as installation is done your mirror will be ready.

P.S. Although I talk about Windows 7 whole post, same procedure will also work on Windows Server 2008 R2. It might even work on earlier Windows versions - I haven’t tried it.