Monthly Archives: September 2011

QuickMon Version 2.3 and Installers

I’ve now updated the QuickMon installers to include some ‘new’ functionality that allows you to choose to install the Windows service as part of the MSI installation.

There are still a few possible quirks – like what happens when you choose not to install the service initially (and do it manually afterwards) or when uninstalling the MSI (without removing the service manually) and then installing a new version ‘and then ‘choosing to install the service. In that case you get an error message that the service is already installed (duh as if you don’t know), the MSI Installer fails and rolls back completely. The solution (one of them) is to simply install the MSI and not choose to install/register the service in Service Manager.

Installers

I’ve learned a whole bunch of new ‘things’ about the standard VS installer during all of this. Mostly how limited the build-in Installer technology is but also some tweaks you can do to still (despite) get something good out of it.

Here is a few tips I came across:

1. When you add a ‘Checkboxes’ custom dialog to the ‘User Interface’ of the installer and want to use the checkbox value as a condition in one of the Custom Action it must look like this e.g: ‘CHKINSTALLSERVICE=1’  (without the quotes). I tried all kind of weird combinations like =”True”, =”1″ etc. that didn’t work…

2. You can have the MSI Installer call the ‘Installer’ classes housed inside your service project (and automatically install it) by adding a ‘Custom Action’ – ‘Install’ action. The default for it is to look for any installer classes inside the assembly. Similarly you can add the same for ‘Uninstall’ but this requires that the service has actually been installed (which is a problem for me since the user can choose not to install it at all)

3. Adding the “-install” and “-uninstall” parameters is nice and all but please remember to run it under an Administrator account (elevated) otherwise it simply fails with an “Access is denied” error. If you understand why then it seems obvious but for people that do not know about this it could be a pain (the error message does not tell you why ‘Access is denied…’)

4. The whole ‘backwards compatibility ID generation thing still baffles me. Upgraded projects (from VS2008 to VS2010) does not show it and the default on VS2010 is false. If not set it seems each time you install a newer version any copy of your shortcuts (like pinned to the taskbar) becomes ‘invalid. This is really a big pain (yes, it is probably easy enough to just unpin/pin again to fix it…)

5. The whole ‘Target platform’ thing is a mess – especially when the solution is under source control. Why do you have to check out the whole project just to change the Target platform setting to rebuild the MSI installer? Why is there not an option to build ‘both’ x86 and x64 at the same time (separate directories or something)?

6. Yes, using a better Installer tool like Wix will probably help… still need to learn how to use it. Anyone have some good tutorials somewhere? 🙂

 

Creating a self installing Windows Service

Being in the business of creating several Windows Services myself (EventScavenger, Event Collector, QuickMon) I started thinking about how to make the whole install and set up process a bit easier and eliminating the manual steps to install a Windows Service.

So what if you can simply run the service ‘exe’ with a “-install” or “-uninstall” parameter and let it do the work for you? Additionally, what if it it can even prompt you for start up type and user account details during the process – all of this without even using installutil…?

Well after some research, testing, trail and error, losing some more hair and eventually finding a way to make it work I now have a way to do all this. Nice thing is it can be used together with an MSI installer as well or even an external app or script.

ProjectInstaller

The trick is to create a custom ProjectInstaller class (not use the wizards that comes with VS to add installers). I’ve added some properties to this class to specify things like Service name, display name, start up type, account type, user name and password.

[RunInstaller(true)]
public class ProjectInstaller : Installer
{

private ServiceProcessInstaller processInstaller;
private System.ServiceProcess.ServiceInstaller serviceInstaller;

#region Added properties
public string ServiceName
{
get { return serviceInstaller.ServiceName; }
set { serviceInstaller.ServiceName = value; }
}
public string DisplayName
{
get { return serviceInstaller.DisplayName; }
set { serviceInstaller.DisplayName = value; }
}
public string Description
{
get { return serviceInstaller.Description; }
set { serviceInstaller.Description = value; }
}
public ServiceStartMode StartType
{
get { return serviceInstaller.StartType; }
set { serviceInstaller.StartType = value; }
}
public ServiceAccount Account
{
get { return processInstaller.Account; }
set { processInstaller.Account = value; }
}
public string ServiceUsername
{
get { return processInstaller.Username; }
set { processInstaller.Username = value; }
}
public string ServicePassword
{
get { return processInstaller.Password; }
set { processInstaller.Password = value; }
}
#endregion

public ProjectInstaller()
{

processInstaller = new ServiceProcessInstaller();
serviceInstaller = new System.ServiceProcess.ServiceInstaller();

Installers.AddRange(new Installer[] {
processInstaller,
serviceInstaller});

}

protected override void OnBeforeInstall(System.Collections.IDictionary savedState)
{

SetContextParameter(“name”, ServiceName);
SetContextParameter(“display”, DisplayName);
SetContextParameter(“desc”, Description);
SetContextParameter(“start”, StartType.ToString());
SetContextParameter(“account”, Account.ToString());

if (Account == ServiceAccount.User)
{

SetContextParameter(“user”, ServiceUsername);
SetContextParameter(“password”, ServicePassword);

}
base.OnBeforeInstall(savedState);

}

public void SetContextParameter(string key, string value)
{

if (!this.Context.Parameters.ContainsKey(key))

this.Context.Parameters.Add(key, value);

else

this.Context.Parameters[key] = value;

}

}

Calling the Installer/uninstaller

In order to get the service executable to handle the -“install” or “-uninstall” parameters I modified the Main method in Program.cs to accept a string parameter array and then call the appropriate method if either of those two parameters are passed.

Example code:

static class Program
{

static void Main(string[] args)
{

if (args.Length > 0)
{

if (args[0].ToUpper() == “-INSTALL”)
{

InstallService();
return;

}
else if (args[0].ToUpper() == “-UNINSTALL”)
{

UnInstallService();
return;

}

}
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new SelfInstallService() };
ServiceBase.Run(ServicesToRun);

}

private static bool InstallService()
{

bool success = false;
try
{

string exeFullPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string workingPath = System.IO.Path.GetDirectoryName(exeFullPath);
string logPath = System.IO.Path.Combine(workingPath, “Install.log”);
ServiceStartMode startmode = ServiceStartMode.Automatic;
ServiceAccount account = ServiceAccount.LocalService;
string username = “”;
string password = “”;

InstallerForm installerForm = new InstallerForm();
installerForm.StartType = ServiceStartMode.Automatic;
installerForm.AccountType = ServiceAccount.User;
if (installerForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{

startmode = installerForm.StartType;
account = installerForm.AccountType;
if (installerForm.AccountType == ServiceAccount.User)
{

username = installerForm.UserName;
password = installerForm.Password;

}

}

Hashtable savedState = new Hashtable();
ProjectInstaller myProjectInstaller = new ProjectInstaller();
InstallContext myInstallContext = new InstallContext(logPath, new string[] { });
myProjectInstaller.Context = myInstallContext;
myProjectInstaller.ServiceName = “SelfInstallService”;
myProjectInstaller.DisplayName = “Self Install Service”;
myProjectInstaller.Description = “Self Install Service test”;
myProjectInstaller.StartType = startmode;
myProjectInstaller.Account = account;
if (account == ServiceAccount.User)
{

myProjectInstaller.ServiceUsername = username;
myProjectInstaller.ServicePassword = password;

}
myProjectInstaller.Context.Parameters[“AssemblyPath”] = exeFullPath;

myProjectInstaller.Install(savedState);
success = true;

}
catch (Exception ex)
{

System.Windows.Forms.MessageBox.Show(ex.Message, “Install service”, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

}
return success;

}

private static bool UnInstallService()
{

bool success = false;
try
{

string exeFullPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string workingPath = System.IO.Path.GetDirectoryName(exeFullPath);
string logPath = System.IO.Path.Combine(workingPath, “Install.log”);

ServiceInstaller myServiceInstaller = new ServiceInstaller();
InstallContext Context = new InstallContext(logPath, null);
myServiceInstaller.Context = Context;
myServiceInstaller.ServiceName = “SelfInstallService”;
myServiceInstaller.Uninstall(null);
success = true;

}
catch (Exception ex)
{

System.Windows.Forms.MessageBox.Show(ex.Message, “Uninstall service”, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

}
return success;

}

}

You might notice I use a custom form ‘InstallerForm’ here which I’m not showing the code for. All it is is a simple Windows Form that allows you to enter or choose some settings that this code is using. I’ll upload some code example a bit later.

Now, you can simple go to the command line (or create a batch file) that calls the service exe with either the “-install” or “-uninstall” parameters.

Update: I’ve added some sample code here. There have been some improvements since the article. It turns out the overridden method OnBeforeInstall is not necessary at all.

In a new blog post I’ve enhanced the functionality to include multi instance functionality. See this.

Firefox 7

And there they release 7. So far can’t see any major differences as far as I’m concern (other than a few broken add-ins which hasn’t been updated)

QuickMon Version 2.2

There has been some updates to my QuickMon tool (or set of tools). Since the last update I’ve added a new collector – the SQL Query collector, enhance the Windows Service to allow multiple monitor packs to be use at the same time and tried to simplify the management user interface.

With the latest changes it is becoming even more useful. Try it out!

Post PC world

I read somewhere this morning (one of the RSS feeds from techreport.com) about someone (not pointing fingers) that made another claim that we are going into the ‘post-pc’ world… Right, I almost burst out in loud laughter!

Definition

So what exactly is a ‘personal computer’? Or more specifically, what do you understand from the words ‘personal’ and ‘computer’? Surely anything that has computing power – like a classical ‘PC’, smart phone, tablet, laptop, abacus 😉 etc. and is a personal ‘possession’ can be classified as a ‘personal computer’… sorta. Yes, even that fancy stupid little iPad/iPhone etc falls under that description. Actually, it is just another iteration of the ‘personal computer’ idea. Nothing more. Move along fruity fanboys.. 🙂

Conclusion

The conclusion I can make about these statements (like mentioned in the first paragraph) is that it is merely a ‘sales’ pitch from someone trying to sell or market something they will get some benefit from. Period.

Desktop computer

Now here is a device that may be becoming a bit ‘old’. But I doubt it will disappear anytime soon. All we really still need from them is to be able to ‘verbally’ respond back to our commands… er wait, that is my 2051 comment for pc’s… Anyway, Don’t always believe what those sales/marketing crooks tell ya. All they really want is your money!

Windows 8 – A couple of follow-up thoughts

I must admit I haven’t done extreme testing or anything hectic with it yet but there are a couple of irritating things about the Windows 8 Developer Preview. Hopefully these will only be issues that is due to the ‘test/beta’ status of Windows 8 and that they improve some things along the way.

At the moment I have two big’ish issues with the Developer Preview.

1. The Metro interface – I don’t have an actual problem with it as such except that you don’t have the option to easily disable it and return to the more classical Windows 7 desktop. It may be great for tablets or other portable devices with touch screens but not on a work related PC – and definitely not for legacy applications.

2. Internet connectivity is absolutely required – Not everyone has super fast and uncapped connections – even today. For me the problem is even worse because I have to run it inside a VM (VirtualBox) on a network where it is not allowed to have such test stuff accessing the Internet. The problem it creates is that this developer preview ‘absolutely’ requires a connection even to do something as simple as adding Windows components (through the add/remove programs control panel). Why it has to go to the Windows Update site just to get something that should be on the local install media is beyond me!

On the positive side I’m really impressed with the boot-up speed. General performance/response is really good (yes, even inside a VM). I only have 2GB memory allocated to it and it doesn’t feel too sluggish – but yes, I’m not running any hectic applications inside it.

Blowing up the planet… kinda..

Nice article from Phil Plait (The guy from Bad Astronomy) wrote an article about the math to do exactly this. Turns out it isn’t that easy (if possible/practical at all) but if you really, really really need to do it….

3 reasons we can’t blow up a planet sci-fi style

There is an easier way to solve the problem of you wanting to ‘kill’ a planet – just leave and find another one that would make you happy. It’s much easier and better (for us still living on this one…)

Development tip for testing

Quick tip for all developers/programmers and anyone involved with creating software…

You haven’t tested your software until you’ve broken it yourself – aka negative testing.

If you couldn’t break your program yourself then… either you’re a super duper crazy developer or someone else will find a way to break it and make you look bad!

 

Windows 8 – Initial impressions

Well, I managed to get the Windows 8 Developer Preview installed (in a VM, see previews post) and my initial feeling is…. {drumroll} well, I like it mostly. There may be one or two little things that is ‘different’ or weird or feels wrong but mostly it looks good and works good.

Unless you have some kind of touch-screen (which I don’t) I doubt I’ll use the ‘Metro’ menu screen much. It may make sense on a phone device or tablet where you can use touch but with the mouse and keyboard – I don’t think so. I’ll fall back to the more traditional start-menu with task bar as soon as I can (when I can figure out how…)

The Windows Task manager has been changed quite a bit. There are lots more information available and the way it has been laid out looks better – What took them so long! 🙂

Unfortunately virtually none of the example apps on the Metro menu work – probably since I don’t have a network connection set up for the VM. Ok, so I figured out that some apps simply fail to start because the screen resolution was too low. A warning message might have been useful.

The Ribbon control in Windows Explorer is actually nice (at least I seem to like it after getting use to ribbons using Office etc). Only pain is the lack of the ‘fine-zoom’ for the View-Layout like we use to have in Windows 7. That was sometime useful because I could resize image thumbnails to something between one of the preset sizes. That is not possible anymore.

Something I had some trouble with initially was how to get a plain command prompt window from Metro. Launching apps from the metro interface that’s not there already is at first not an obvious thing. Then I discovered that just by starting typing in the keyboard the search functionality kicks in and you should find what you’re looking for. I just wonder how good it would be for things that are not in any paths included by the search engine…

Another thing I could not initially figure out is how to get the machine to do a shutdown… Weird I know but apparently it is only available after you logged off or go to the ‘Settings’ screen and click on the ‘Power’ button. Perhaps in the tablet/phone world you might want to use different ways to put the machine to ‘bed’ but for a PC where you don’t want it running all the time this is a pain.

Well, let my ‘play’ some more…

So far so good Windows 8 team 🙂

 

Update: One thing I forgot to mention – which is more a VM/VirtualBox issue, is that hardware virtualization must be enabled in the BIOS otherwise things don’t work so lekker… switching off hw-virtualization is possible but then things would be real slooooowwww’

Another Update: If you like to disable the Metro interface and return to the more ‘classical’ Windows 7 look try this (at your own risk): rename C:\Windows\system32\shsxs.dll to something like shsxs.old (but don’t delete it in case you have to restore it)

Windows 8 Developer Preview in a VM

Well, I managed to download the developer preview (full 64-bit one) and tried to run it using VirtualBox. Unfortunately the standard settings of VirtualBox doesn’t work for this Beta/Alpha/Test version for Windows but fortunately someone managed to figure out how to change the settings to at least get this VM started (without the lovely new BSOD)

See http://forums.virtualbox.org/viewtopic.php?p=200748

Now touch wood everything else in the set up works.