Streaming media from Samba share to Android

Like many, I have a server/NAS that contains all my media (movies, music, photos, documents etc.), which is accessible via a Samba share to PCs in my house via LAN/wifi. XMBC works great to view all the media on-demand on the TV, however I was looking for a way to stream the media to an Android tablet (Samsung Galaxy Tab 10.1). And I found a REALLY simple, free solution:

  1. Install ES File Explorer (free) from the Android Market.
  2. Install RockPlayer Lite (free) from the Android Market.
  3. Open ES File Explorer and change view to LAN, then hit ‘New’ then ‘Server’ (from menu).
  4. Enter your server/NAS IP address, then a forward slash, then your share name, and any credentials if necessary.
  5. Hit OK, now you should be able to browse all the files on your Samba share with ease.

Now, when you tap on a movie file (avi/mpg/wmv etc.), you will get a prompt to choose which video player to use. Select RockPlayer Lite, and your movie will start playing within a few seconds. I’ve tested this for a variety of movie file types and sizes and RockPlayer Lite works really well, including skipping forwards and backwards through movies. For HD movies, expect to wait a little longer for the movie to buffer before it begins to play (e.g. > 10 seconds), once it gets going it seems pretty stable (no buffering). I’ve also tested this approach on an Android smartphone (LG P500 Optimus One, as well as the Samsung Galaxy S, both running Android 2.2) and it works just the same on the phone as the tablet). Awesome! And of course, you can also use this approach to play music and view photos from your server anywhere in range of your wifi signal 🙂

Can iPad do that!? :p

Magic command to install Asp.Net 4 for IIS 7.5

After creating an ASP.NET web application in Visual Studio, to host it in a freshly installed IIS 7.5, you need to do two things that are not immediately obvious:

  1. Create a new app pool or change the default app pool to target .NET 4 (see IIS->Application Pools).
  2. Run this from the command line:
    %windir%Microsoft.NETFrameworkv4.0.30319aspnet_regiis.exe -i

MSDN has more info on aspnet_regiis command line options here.
Just putting this on my blog so I can remember this magic command line.

Interop.ComAdmin exception when using IIS on a 64-bit OS

If you install IIS on a 64-bit operating system, you may get the following error when navigating to your website locally:

Could not load file or assembly ‘Interop.COMAdmin’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly ‘Interop.COMAdmin’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

The clue here is the BadImageFormatException, which hints that this is a 32/64 bit issue. To fix it, in IIS Services Manager, go to Application Pools, select the application pool under which your website/application is running, and choose ‘Advanced Settings’. Change ‘Enable 32-bit Applications’ from False (the default) to True. Recycle your app pool, and reload your browser page, no more error!

Remote Desktop via VPN

For many programmers and IT professionals, remote access via VPN to machines in their corporate network is a routine activity. This activity usually involves launching a VPN client (e.g. ShrewSoft VPN Client), entering a password, waiting for the VPN to be connected, then launching the remote desktop client. I have written a small executable to help automate that process, called DirectToDesktop.

The program launches your VPN client with the specified arguments and then starts a remote desktop session to a specified computer as soon as that machine can be pinged.

Usage

DirectToDesktop.exe <pathToVpnClient> <vpnClientArgs> <hostName> [pathToLookAlive]

<pathToVpnClient> – E.g. “C:\Program Files\ShrewSoft\VPN Client\ipsecc.exe”
<vpnClientArgs> – Args to pass to the VPN client.  E.g. “-r \”Your Company.pcf\””
<hostName> – The name/IP of the computer inside the VPN to remote desktop to.
[pathToLookAlive] – (optional) Install Look Alive to view connectivity status of the remote computer in the system tray.  E.g. “C:\Program Files (x86)\Zorn Software\Look Alive v1.24\LookAlive.exe”

Note: I’ve only tested the program with the built-in Windows 7 VPN client and ShrewSoft VPN Client, but in theory it should work with any VPN client that accepts command line arguments.

Installation
Just save DirectToDesktop.exe to any location on your hard disk, and add a shortcut to it using the above command line arguments. Run the executable without passing any arguments to view a help/about window.

Example Usage
After you have set up a VPN connection, you can use the following syntax if you are using either of the following clients:

Windows 7 VPN client:

directtodesktop.exe rasdial "Your VPN Profile Name" YourRemotePCNameOrIp

ShrewSoft VPN client:

directtodesktop.exe "C:\Program Files\ShrewSoft\VPN Client\ipsecc.exe" "-r \"Your Company.pcf\"" YourPCName

Windows 7 disconnected network drives

Mapped network drives have always been a buggy area in Windows, probably at least in part because they are still linked to a DOS namespace. From MSDN:

On Windows Server 2003 and Windows XP, the WNet functions create and delete network drive letters in the MS-DOS device namespace associated with a logon session…

Whatever the reason, it is commonly reported that mapped network drives appear as ‘disconnected’ in Windows Explorer (or ‘unavailable’ via net use), and that programs that attempt to use these drive mappings will fail until the user physically clicks on the drive letter in Windows Explorer. Only this user-initiated action will restore the connection and allow other programs to successfully read from the drive letter.

The dreaded disconnected network drive balloon.

This is a BIG problem!

I initially thought that the mapping of the network drives was being done before some required services had started (such as the Workstation and Server services), so I wrote a program to run on startup that attempted to map a drive and logged all the currently running services if it failed. It would keep trying to map a drive until it succeeded. I hoped it would show me which services needed to be running in order to map a drive, after which I would write a program to wait for those services before attempting to map anything. But, much to my amazement, I found that when the initial drive mapping failed and a subsequent attempt succeeded, the set of running services had not changed! So I could only conclude that there was another element in the equation. After thinking about this for a while, and reading this post, which indicates that Microsoft is apparently trying to address this, I decided ‘stuff it’, I’ll just write something that I know will work and is simple.

So I’ve written a small executable called MapDrive.exe to ‘work around’ this problem, described on the following dialog:

About MapDrive

Now as you may know since Vista, there is the concept of a split user token, and mapped network drives apply to only one token, so if you map drives as a standard user and then run an elevated process, those network drives are not available to the elevated process. This behaviour is documented by Microsoft, however the solution they offer is both unsupported and unsafe. Other solutions have been proposed here. If you don’t wish to use any of these solutions, you can do this:

1. Run MapDrive.exe as a shortcut from your Startup folder. This will map drives for the standard user token.
2. Run MapDrive.exe as a local group policy logon script using gpedit.msc. This will map drives for the administrator token.

Note: After using this program, you may still see the above balloon popup, simply click the spanner icon, and select ‘Hide icon and notifications’ for ‘Windows Explorer’.

Download the utility for free here.

UPDATE: A few people have asked how to use this program. As stated above, there are two ways, depending on whether you need drives mapped for standard users or admins. If you don’t know what you need, you probably just need to do this for standard users. Here are the steps for both:

1. Copy MapDrive.exe to somewhere on your local hard drive.

Standard Users:
2. Right-click MapDrive.exe and choose ‘Create Shortcut’. This will create a file called ‘MapDrive.exe – Shortcut’ next to MapDrive.exe. Now go Start->All Programs, right-click the ‘Startup’ folder and choose ‘Open’. Now copy the shortcut file you made before to this folder. Now right-click the shortcut file and choose ‘Properties’. Add the drive letter and network share as argument to the end of the ‘Target’ field e.g. “C:\Users\joeblogs\Documents\MapDrive.exe s: \\server\share 20”. You are done, next time you reboot, your s: should be mapped successfully for standard users.

Admin Users:
3. Press Win+R, type gpedit.msc, go User Configuration->Windows Settings->Scripts. Double-click Logon, click ‘Add’ and enter script name (no quotes): “C:\Users\joeblogs\Documents\MapDrive.exe” and script parameters (no quotes): “s: \\server\share 20”, ok, ok, done. You are done, next time you reboot, your s: should be mapped successfully for admin users (i.e. elevated programs).

Network CHMs = Pain courtesy of IE

Despite being around since 1997, CHM files still remain a popular format for program help / documentation as well as ebooks. But opening them from a network drive was outlawed in 2005 after Microsoft released this security update. There was a registry hack workaround to enable it again, however this no longer works in Windows 7. The solution accepted on this thread involves two steps:

1. Add this registry key:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions]
"MaxAllowedZone"=dword:00000001

2. In Internet Explorer->Tools->Internet Options and add your network drive into the safe/trusted zones.

Just the thought of firing up IE gives me the security-shivers and I really don’t want to be messing about with ‘trusted zones’ – I don’t trust IE to do anything. I’m surprised the US government hasn’t yet advised its citizens against using IE, like Australia, France and Germany have.

Of course the whole reason this has anything to do with IE is because the built in HH.exe that is the default Html Help viewer on Windows uses IE as the web browser engine to display and navigate the HTML files inside the CHM. So we could avoid this whole problem if there was a CHM viewer that doesn’t use IE at all. Now to the motivation for this post:

Enter xCHM – this is an open-source project that predominantly provides support for viewing CHM files on non-windows platforms, however it has been ported to Windows, so you can kiss HH.exe goodbye, and open your CHMs from any network location without having to hack your registry or mess with IE zones!!

Download the Windows port of xCHM (look under xCHM for Win32).

Internet over copper sucks

I am subscribed to the fastest available ADSL 2+ (24Mbps) connection here in Sydney, and my connection at three different houses I’ve lived in has always been unreliable.  Currently where I’m living, the connection actually goes down whenever it starts raining!  😕  It also frequently goes down just at random, when it’s not raining.  P2P seems to worsen the situation (not surprisingly), but usenet is superior anyway, so that’s not a problem anymore.  Granted, I am pretty far from the exchange (~4km), hopefully copper will be replaced with optic fibre in the next decade.

So a while back I wrote a small utility that shows an icon in the system tray reflecting whether you can contact (via ping) a remote host (google, or your ISP’s DNS server, for example).

Online icon: lookalive-up

Offline icon: lookalive-down

Clicking the icon shows your the history of ping times:

Look Alive

It can be run on startup, passing the name or IP of the remote host as an argument.  For example:

"lookalive.exe www.google.com"

You can also specify the period (in seconds) between pings (default is 1 second), so to ping www.google.com every 5 seconds:

"lookalive.exe www.google.com 5"

If you have multiple hosts you wish to ping, you can run the application multiple times and a spearate icon in the system tray is displayed for each host. To distinguish between them, you can pass a colour:

"lookalive.exe www.google.com 5 blue"

Additional arguments allow calling of an external application and/or showing a balloon notification whenever the state changes and customisation of the system tray icon.

Download the utility for free as an installer or as a standalone EXE.