Archive

Author Archive

Adjust Linux Mint Mouse Scroll (Normal/Reverse)

December 8th, 2011 3 comments

When you install Linux Mint and install the Mtrack Multitouch drivers, as explained here. Or through the script explained in my other blog post, found here. You will have the system mouse scroll setup in the same manner as Mac OSX Lion, which is the opposite to what everyone has been using until now.

Continue reading “Adjust Linux Mint Mouse Scroll (Normal/Reverse)” »

Triple Boot 13inch MacBook Air 4.2 (2011 model)

December 5th, 2011 7 comments

After recently purchasing a MacBook Air 4.2 (2011 model) I decided it would be great to triple boot with MacOS, Windows 7 and a linux distro. After some googling I found this great article on lifehacker. This how-to follows this guide, but has been modified slightly for my installation.

Continue reading “Triple Boot 13inch MacBook Air 4.2 (2011 model)” »

Install Linux Mint 12 (Lisa) on 13inch MacBook Air 4.2 (2011 model)

December 5th, 2011 27 comments

Linux Mint 12 (Lisa) is based on Ubuntu 11.10 so the script created by Joshua Dillon that is referenced on the Ubuntu MacBook Air site would in theory work, however as I found I needed to do a little tweaking to get this to occur. Below are the steps that enabled me to run Mint 12 on my MacBook Air.

Continue reading “Install Linux Mint 12 (Lisa) on 13inch MacBook Air 4.2 (2011 model)” »

C# Check If Application Is Already Running Then Set Focus

October 6th, 2011 9 comments

Here is a simple code snippet to assist in determining if another instance of the application is running. If there is another instance then close the current one and provide focus to the already running process.

I located this code on a forum, link here

Continue reading “C# Check If Application Is Already Running Then Set Focus” »

T-SQL CASE Statement checking for NULL

July 17th, 2011 5 comments

I have found after much annoyance, that an SQL query I had in production was incorrectly checking for NULL in my SQL statement.

This is a simple school-boy error that I will now never do again.

The issue is that if you have a case statement as follows:

CASE WHEN <Value to check> = NULL
    THEN <Value to replace NULL>
    ELSE <Value that is not null>
END

This will always return NULL when there is a NULL value that is in the value check.

However, all you need to do is change the ‘=’ to an ‘IS’ and it will calculate correctly

CASE WHEN <Value to check> IS NULL
    THEN <Value to replace NULL>
    ELSE <Value that is not null>
END
Categories: T-SQL Tags: , , , , , , , ,

Add/Enable Compound TCP (CTCP) Flow to Windows 7

June 16th, 2011 Comments off

By default the windows TCP stack does not have any Flow control enabled. These are algorithm’s that can ensure you get the most out of your TCP connection.

To enable this feature on Windows 7

netsh interface tcp set global congestionprovider=ctcp

To disable this feature:

netsh interface tcp set global congestionprovider=none

To show the current settings

netsh interface tcp show global

More information contained here

Categories: Windows Tags: , , , ,

Passing parameters collected in dialog to Custom Action in msi C#

May 14th, 2011 Comments off

I was a little lost to why the dialog boxes I was adding to my windows installer msi was not being passed to my custom action.

There is a very simple item that I overlooked, and that is you must specify what values you want sent to your custom action.

On the properties of the custom action, there is a property called CustomActionData.

The format of this properties is:

/ParamName1=”[DIALOGPROPERTY1]” /ParamName2=”[DIALOGPROPERTY2]” …. etc

Custom Action Properties

Custom Action Properties

Then to use the parameters you will use the following code:

string sqlServer = Context.Parameters["ParamName1"];
string username = Context.Parameters["ParamName2"];
string password = Context.Parameters["ParamName3"];

C# Determine if 64bit or 32bit OS Version

May 14th, 2011 1 comment

I have had an issue where I needed to determine if the executing windows os version was either 32bit or 64bit, and as you can execute a 32bit process on a 64bit system this is a little more difficult then first thought to achieve.

The other condition that this class must have is to execute on all versions of windows and not rely on something that will only execute above a certain version.

After some digging around on google, I found this question on StackOverflow, that went into quite some detail about the different methods that work and will not work. I would suggest a read so you understand the implications of different implementations.

I have settled for a class that has been built around what I found on this question, that will:
1. Determine the os version
2. Run on all versions of windows.

using System;
using System.Runtime.InteropServices;

namespace Testing.Helpers
{
    public static class OsVersionHelper
    {

        // Will return result of 64but OS on all versions of windows that support .net
        public static bool Is64BitOperatingSystem()
        {
            if ( IntPtr.Size == 8 ) //64bit will only run on 64bit
            {
                return true;
            }

            bool flag;
            return (DoesWin32MethodExist("kernel32.dll", "IsWow64Process") && IsWow64Process(GetCurrentProcess(), out flag)) && flag;
        }

        private static bool DoesWin32MethodExist(string moduleName, string methodName)
        {
            IntPtr moduleHandle = GetModuleHandle(moduleName);
            if (moduleHandle == IntPtr.Zero)
            {
                return false;
            }

            return GetProcAddress(moduleHandle, methodName) != IntPtr.Zero;
        }

        [DllImport("kernel32.dll")]
        private static extern IntPtr GetCurrentProcess();

        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        private static extern IntPtr GetModuleHandle(string moduleName);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr GetProcAddress(IntPtr module, [MarshalAs(UnmanagedType.LPStr)]string procName);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool IsWow64Process(IntPtr process, out bool wow64Process);
    }
}

C# Start/Stop/Restart Windows Service Remotely or Locally

May 13th, 2011 5 comments

Below is a very basic implementation of a class that runs within a Windows Form, to Start, Stop and Restart a windows service.

I have not included checking for other service states other than Started and Stopped, this could be extended. If you are using this to control a windows service on a remote PC, you need to ensure that the user account you are executing this from has high enough privileges to Start and Stop a service.

Updated Download of Sourcecode

Edited: 13th May 2011 –> After some imperfections, I have updated the code as shown below and in the download link above.

Fields and Constructors of Class


private const int RestartTimeout = 10000;

private readonly ServiceController service;

public Control(string serviceName, string computerName)
{
    service = new ServiceController(serviceName, computerName);
}

public Control(string serviceName)
{
    service = new ServiceController(serviceName);
}

Start Windows Service:


public bool StartService()
{
    try
    {
        service.Refresh();

        if (service.Status == ServiceControllerStatus.Stopped)
        {
            service.Start();
            return true;
        }

        MessageBox.Show(string.Format("{0} --> already started", service.DisplayName));
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString(), @"Error Starting Service");
    }

    return false;
}

Stop Windows Service:


public bool StopService()
{
    try
    {
        service.Refresh();

        if (service.Status == ServiceControllerStatus.Running)
        {
            service.Stop();
            return true;
        }

        MessageBox.Show(string.Format("{0} --> already stopped", service.DisplayName));
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString(), @"Error Stopping Service");
    }

    return false;
}

Restart Windows Service


public bool RestartService()
{
    try
    {
        service.Refresh();

        if (service.Status != ServiceControllerStatus.Stopped)
        {
            service.Stop();

            int i = 0;
            while (service.Status != ServiceControllerStatus.Stopped)
            {
                service.Refresh();
                Thread.Sleep(100);
                i++;

                if (i >= RestartTimeout / 100)
                {
                    MessageBox.Show(@"Restart Stop Timeout Exceeded");
                    return false;
                }
            }

            service.Start();
            return true;
        }

        service.Start();
        MessageBox.Show(string.Format("{0} --> was stopped, service has been started", service.DisplayName));
        return true;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString(), @"Error Restarting Service");
        return false;
    }
}

C# Update app.config in msi custom action

May 12th, 2011 3 comments

I have been doing quite a lot of googling about updating the app.config file during an installation using an msi custom action. I found this blog by Rob Aquila, however this did not really work for me.

I then came across this question on StackOverflow that almost solved the problem. The key to the solution was to open the app.config and save directly to this file.

The issue I found with the later solution is that for some reason I could not get the Context.Parameters = “targetdir”. When the install was running this was always returning null.

So my solution that worked for me is as follows:

public override void Install(System.Collections.IDictionary savedState)
{
    base.Install(savedState);

    var targetAssembly = Context.Parameters["assemblypath"];

    var path = string.Format("{0}.config", targetAssembly);

    var xmlDoc = new System.Xml.XmlDocument();

    xmlDoc.Load(path);

    var node = xmlDoc.SelectSingleNode("/configuration/userSettings/Application.Properties.Settings/setting[@name='SettingName']/value");
    node.InnerText = "PLACE NEW PARAMATER HERE";

    xDoc.Save(path);
}

Thank you to Khalil Dahab for his response on StackOverflow

%d bloggers like this: