Stuff to pimp your Windows Home Server

Hacking Windows Home Server is a blog dedicated to Microsoft's WHS technology. Brought to you by Donavon West, Microsoft MVP and author of LiveGadgets.net and donavon.com I'll also discuss the Hewlett-Packard HP MediaSmart Server EX470, EX475, EX485, EX487, the T7-HSA Tranquil Harmony Home Server and any other new Home Server hardware platforms that arise. You can also call this hacking or hackz. In any case I will show you some cool things to make your Microsoft Windows Home Server even sweeter.

A blog devoted to getting the most out of your
Windows Home Server by Microsoft MVP Donavon West.

Saturday, June 20, 2009

Code: Load the WHS Console in Whatever Language you Choose

 image

This is the first in what I hope is a series of articles on coding for Windows Home Server. In my first article, I'm not coding an Add-In. Instead I'll show you how to load the Windows Home Server Console using any language (or more appropriately stated: Culture) that you desire.

This is of little use for the casual user as the actual console itself (or at least Microsoft's portion) is still in English, but Add-In developers should find this extremely useful. The reason I wrote the loader was that I needed a way to test my twitter Add-In @WHSTweet as I have it translated into German, French and Spanish.

Here is the HP tab of the Windows Home Server Console after I have loaded it in French:

image

Now let's go through just how we build our project. You can also download the complete Visual Studio 2008 solution and follow along at home. But first a word of caution. Whenever messing around with RDPing into your WHS or messing with files in the Windows Home Server folder, you run the risk of messing something up. You my want to do this on a Virtual Machine instead of a production server. Personally I use my production server with all of my important family photos, but my middle name is "Danger". :)

You've been warned, now let's get started:

  1. Load Visual Studio 2008 and create a new C# Windows Application named WHSCultureLoader.
  2. Add a Label with the Text of "Choose a Culture"
  3. Add a ComboBox and change the DropDownStyle to DropDownList.
  4. Add a Button with the Text of "Execute".
  5. Right click on the designer background and select View Code.
  6. Add the following code to Form1 constructor so that it look as follows. What we are doing here is loading the ComboBox with all known Cultures.
    1. public Form1()
    2. {
    3.     InitializeComponent();
    4.     CultureInfo[] ciArray = CultureInfo.GetCultures(CultureTypes.AllCultures);
    5.     foreach (CultureInfo ci in ciArray)
    6.     {
    7.         comboBox1.Items.Add(ci);
    8.     }
    9.     Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
    10.     comboBox1.DisplayMember = "DisplayName";
    11.     comboBox1.SelectedItem = Thread.CurrentThread.CurrentUICulture;
    12. }
  7. Next go back to the Designer and double click on the Execute button. This will create an empty the button1_Click function. Add the code as follows:
    1. private void button1_Click(object sender, EventArgs e)
    2. {
    3.     Form f;
    4.     CultureInfo ci = comboBox1.SelectedItem as CultureInfo;
    5.     Thread.CurrentThread.CurrentUICulture = ci;
    6.     try
    7.     {
    8.         string path = Path.GetDirectoryName(Application.ExecutablePath);
    9.         Assembly a = Assembly.LoadFile(path+"\\HomeServerConsole.exe");
    10.         f = (Form)a.CreateInstance(a.EntryPoint.ReflectedType.FullName);
    11.     }
    12.     catch (Exception ex)
    13.     {
    14.         MessageBox.Show(ex.Message);
    15.         return;
    16.     }
    17.     this.Hide();
    18.     f.KeyPreview = true;
    19.     f.FormClosed += new FormClosedEventHandler(f_FormClosed);
    20.     f.Show();
    21. }
  8. In lines 5 and 6 we set the thread's UI culture to the one selected in our listbox.
  9. Next we load the assembly HomeServerConsole.exe from the same path as WHSCultureLoader.exe executed from.
  10. In line 12 we create an instance of MainForm, the main form in the Windows Home Server Console.
  11. In line 20 we hide our selection form.
  12. In line 22 we specify that the form is to receive key events before they are passed to any controls.
  13. In line 23 we setup a handler so that when the form closes, we exit the application.
  14. And finally in line 24, we show the Windows Home Server Console form.
  15. Here is the code for the close handler.
    1. void f_FormClosed(object sender, FormClosedEventArgs e)
    2. {
    3.     Environment.Exit(0);
    4. }

Now lets test our code. Build the project and copy WHSCultureLoader to the \Program Files\Windows Home Server folder on your WHS. You will need to RDP into your WHS to run this loader. It does NOT run from the client. Launch WHSCultureLoader.exe and you should see our main form.

image

Change the Culture to something like French (France) and click Execute. If a few moments the Windows Home Server Console will load. If you are running on an HP MediaSmart Server, you should notice two things. One is that the HP tab is not the first/leftmost tab loaded. This is due to the fact that the HomeServerConsole.exe.config file was not loaded. This file instructs HomeServerConsole.exe on tab order. Here is the config file that ships with the HP:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <configuration>
  3.     <appSettings>
  4.       <add key="MediaSmart Server"     value="1" />
  5.     </appSettings>
  6. </configuration>

OK, now that we've gotten completely off track, lets continue. The other thing that you will notice is that any Add-Ins that support French (most notably the HP tab) are actually IN FRENCH! The same goes for German and Spanish or at least that's what HP supports in their standard language pack DLLs that they ship to customers in the United States.

Unfortunately, Microsoft does not ship language DLLs for the Windows Home Server Console itself, so any Microsoft code or Add-In will still be in English (or whatever language that your SKU of Home Server is in).

I hope you have enjoyed my first WHS Coding Series article.

Fin. Why not comment on what you've just read or even Digg It!

Microsoft Social Bookmark on Microsoft Social

1 comments:

mike_nl said...

Hi Donavon,
very interesting peace of coding. When you have one moment a little bit free time, please contact me mike_nl @ web . de.

Post a Comment