Saturday, March 27, 2010

XBMC for Xbox – how to disconnect an FTP connection

You might have the case where you are transferring files to your Xbox Media Center and it gets disconnected (usually through wi-fi) and when your FTP client will try to re-connect it will be denied, as there are only two simultaneous connections allowed, you will have to wait for a minute (the default timeout) or reboot the Xbox.

If you don’t want to wait or if your Xbox is in the other room, here is how you can close those hung connections from your Windows PC.

To allow remote admin connections, connect through FTP, download Q:\System\FileZilla Server.xml and edit on your PC to change the Admin IP Addresses to match your network IP address class (in my case, 10.0.0.* - default is 192.168.0.*), then upload back.

Install an older version of the FileZilla Server like. 0.8.9 from here - that is because the protocol has changed in later versions. You can uninstall the application and only keep the FileZilla Server Interface.exe if you want.

Run the FileZilla Server Interface and connect to your Xbox (default password is xbmpzilla, it can also be changed in the above XML configuration file).

On the right side you will see the active connections, right click one of them and use “Kick” to disconnect. Simples!

An added benefit from using the FileZilla Server Interface is that now you can change server settings without having to download and edit the XML configuration file every time ;-) not that you should need to, but but might be useful.

Single Instance Application in C# (per session)

Sometimes you want to only allow for a single instance of your application and that can be accomplished by using a Mutex class. On top of that, if it’s used on a Terminal Server / Citrix, you also want to check the session id, to ensure you’re not interfering with other user’s instances or even the same user on a different connection.

EDIT: On a second read, the SID might not be needed in the mutex name, as by default the mutex is local, unless told otherwise, see note below:

* * *

[return: MarshalAs(UnmanagedType.Bool)] 
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); 
[return: MarshalAs(UnmanagedType.Bool)] 
static extern bool SetForegroundWindow(IntPtr hWnd);
// Constants 
const int SW_RESTORE = 9;
/// <summary> 
/// The main entry point for the application. 
/// </summary> 
static void Main() 
  // Use a Mutex to allow only one instance per session...  
  bool   newInstance = true; 
  String mutexId     = String.Format("APP={0}; SID={1}",
  Mutex mutex = new System.Threading.Mutex(true, mutexId, out newInstance);  
  if (!newInstance) {
    MessageBox.Show("Application Already Running!" + mutexId);
    // Find the instance holding the mutex and restore...  
    Process currentProcess = Process.GetCurrentProcess();  
    foreach (Process process in Process.GetProcessesByName(currentProcess.ProcessName))  
      if (process.Id        != currentProcess.Id &&  
          process.SessionId == currentProcess.SessionId)  
        // Restore window (if minimized)... 
        ShowWindow(process.MainWindowHandle, SW_RESTORE); 
        // Set foreground window... 
  // Run normal...  
  Application.Run(new MainForm()); 
  // Hold the mutex from being garbage collected... 


Saturday, March 20, 2010

XBMC Python tips – how to get build version & date

Python code:

import xbmc
result = xbmc.executehttpapi('GetSystemInfo(120;121)')
system_info    = result.split('<li>')
print "Version = " + system_info[1]
print "Date    = " + system_info[2]


import xbmc
result = xbmc.executehttpapi('GetSystemInfoByName(system.buildversion;system.builddate)')
system_info    = result.split('<li>')
print "Version = " + system_info[1]
print "Date    = " + system_info[2]

or even a simpler alternative, suggested by BigBellyBilly:

import xbmc
version = xbmc.getInfoLabel('System.BuildVersion')
date    = xbmc.getInfoLabel('System.BuildDate')
print "Version = " + version
print "Date    = " + date

Result :

Version = 9.11 r26017 
Date    = Dec 23 2009


Wednesday, March 3, 2010

Windows 7 system waking up at night

A common reason for a computer to wake up is that a network interface was configured to Wake on LAN (WoL) (usually company computers) – that means it can wake up due to a link change signal or a Magic Packet. This feature can be quite useful if you want to wake up your work computer, first logon through the company VPN and then run a WoL software from one of the Citrix / Terminal Server sessions (usually WoL packets are not allowed through gateways from the Internet). Nowadays even wireless network devices allow for WoL (depending on BIOS and motherboard).

To disable (or enable) WoL, see this article below for more details – simply check/uncheck the the box that says “Allow this device to wake the computer” accordingly. The “Only allow management stations to wake the computer”  I believe it means to wake up only on Magic Packet requests.

Another reason for your Windows system waking up, and probably more common to Windows 7 editions including Media Center (e.g. Professional), is that if the computer supports APM 1.2 or later it is possible to have tasks that can wake up the system from S4 (Hibernation) or S5 (Power Off) – most common seems to be the case with the Media Center Update scheduler task – see more details below.

Notice the “Wake the computer to run this task” is checked - either uncheck the box (double click the task scheduler entry to edit) or simply disable the task altogether.