Archive

Posts Tagged ‘C#’

Firefox Simple Starter Program

September 6th, 2007

Are you developer? or beginner to programming?
You can write you own starter program and produce a new fresh Firefox.exe and Thunderbird.exe to run your portable firefox and thunderbird. Please note, if you want to walk through this article you should have done the walk with the previous articles first.

When you are ready, continue on..

Requirements

  • Minimal knowledge on csharp language
  • Microsoft .NET framework installed
  • Development IDE ( SharpDevelop ) installed
  • Completed the walkthrough in previous articles

I wrote these codes with .NET framework 2.0 installed on my machine.
However it should work on .NET framework 1.0+ (not tested)

Ok.. let's begin,

  • Startup your SharpDevelop IDE
  • Create New Window Application project, let's call it PMozilla (Portable Mozilla)
  • You should have Program.ch and a few other created automatically
  • Add new class AppStarter.ch
  • Copy and paste the following code and save it
    File: AppStarter.ch
using System;
using System.Diagnostics;
using System.ComponentModel;
 
namespace PMozilla
{
 ///
 /// Description of AppStarter
 ///
 public class AppStarter
 {
  Process proc = null;
  public AppStarter()
  {
   proc = new Process();
  }
 
  public void startFirefox()
  {
   try {
    proc.StartInfo.FileName = "./Firefox/firefox.exe";
    proc.StartInfo.Arguments = "-profile ./_profiles/firefox";
    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    proc.StartInfo.CreateNoWindow = true;
    proc.Start();
   }
   catch (Win32Exception e)
   {
    e.GetBaseException();
   }
  }
  public void startThunderbird()
  {
   try {
    proc.StartInfo.FileName = "./Thunderbird/thunderbird.exe";
    proc.StartInfo.Arguments = "-profile ./_profiles/thunderbird";
    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    proc.StartInfo.CreateNoWindow = true;
    proc.Start();
   }
   catch (Win32Exception e)
   {
    e.GetBaseException();
   }
  }
 }
}
  • Replace Program.ch with the following codes
    File: Program.ch
using System;
using System.Windows.Forms;
 
namespace PMozilla
{
 ///
 /// Class with program entry point.
 ///
 internal sealed class Program
 {
  ///
  /// Program entry point.
  ///
  [STAThread]
  private static void Main(string[] args)
  {
   AppStarter ast = new AppStarter();
   ast.startFirefox();
  }
 }
}
  • Save project
  • Build project, make sure there's no error
  • Now go to your project debug Directory (ie. PMozilla\bin\Debug)
  • You should see PMozilla.exe
  • Copy this file and paste it in your portable firefox directory. Put it outside directory containing firefox.exe
  • Rename PMozilla.exe to Firefox.exe
  • Now double click on a new Firefox.exe
  • A portable Firefox should start.

Create another one for Thunderbird

  • Go back to your IDE and open the same project if it's closed
  • Modify Program.ch
  • Replace ast.startFirefox(); (line 18) to ast.startThunderbird();
  • Now, Save project
  • Build project, make sure there's no error
  • Now go to your project debug Directory (ie. PMozilla\bin\Debug)
  • You should see PMozilla.exe
  • Copy this file and paste it in your portable thunderbird directory. Put it outside directory containing thunderbird.exe
  • Rename PMozilla.exe to Thunderbird.exe
  • Now double click on a new Thunderbird.exe
  • A portable Thunderbird should start.

FAQ & Tip, Programming ,