Get Filezilla to preview images in Windows Photo Viewer without inheriting default programs from windows

Woah, didn’t I just write a post, and now another one, ok people here’s what’s going down. Usually on say a windows 7 machine, when you open an image it opens up in Windows Photo Viewer, if you’ve installed other graphics programs it may open in that if you have set it to when installing. But if like me you like to open images in a lightweight program to view as quickly as possible then you have unchecked those boxes on installing new software.

Now what happens when you want a ftp program like FileZilla to view images on your server with this program? The simple answer is to check the box by inherit from windows, but what if you don’t like that option because other files will open in their default!

I like php, html and aspx files to view in notepad++ or even plain old notepad when checking what the version the server has, and so I want to specify what programs my files open in when usually I like them to open in Visual Studio or DreamWeaver for code completion.

I’m getting to the point now, Windows Photo Viewer doesn’t have an exe for FileZilla to point to and do this, it has a dll and it can be run from the command line with rundll32. As far as I know you can’t get FileZilla to play nice with the commands to open in the Photo Viewer. So here’s a simple windows console application that will be an exe for FileZilla to point to and be happy.

You’ll have to create this yourself as I don’t like the idea of someone downloading an exe they don’t know or trust, and you shouldn’t. but if you see the code and compile it you will know it is safe ^_^

Right, I’m using visual Studio, you can get a free visual c# express if you don’t have the luxury of a work or student license for the full product.

Create new console application and in Program.cs at the top with the using statements add using System.Diagnostics;
now change the main function static void Main(string[] args) to look like the following code


static void Main(string[] args)
{

    if (args.Length > 0)
    {
        if (args[0].ToString().EndsWith(".jpg") || args[0].ToString().EndsWith(".png") || args[0].ToString().EndsWith(".gif") || args[0].ToString().EndsWith(".tif"))
        {
            ProcessStartInfo startInfo = new ProcessStartInfo("cmd", "/c" + "rundll32 \"C:\\Program Files\\Windows Photo Viewer\\PhotoViewer.dll\" ImageView_Fullscreen " + args[0].ToString());

                    

            // this should hide the cmd window right after loading image
            startInfo.UseShellExecute = false;
            startInfo.CreateNoWindow = true;

            //create a process
            Process proc = new Process();
            //assign it our startinfo er info
            proc.StartInfo = startInfo;
            //and start the bad boy
            proc.Start();
        }
        else
        {
            //keep the console window open to show helpful message
            Console.WriteLine("Was expecting an image file type of jpg, png, gif, tif");
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
    else
    {
        //keep the console window open to show helpful message
        Console.WriteLine("Was expecting an argument of an image file with type jpg, png, gif, tif");
        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }
}

This checks for image files passed to it and opens up a new process with cmd rundll32 and the image viewer. Make sure the Windows Photo Viewer path is the same for you by navigating in windows explorer. run it, debug it whatever, then take the exe file from the “/bin/Debug/” directory and put it somewhere you can use FileZilla to reference. If a file of the right type isn’t passed to out console application we write a message to console and then ask the console to read input from the user, this is so the window waits to display a helpful message.

Now in Filezilla, go to edit > settings and under “file editing” check Use filetype associations if available. Then in filetype associations > “custom filetype associations” type jpg “” and now FileZilla will run that exe with the image filename in its temporary location for our app to load the Windows Photo Viewer with Huzzah.

Was this worth it? probably not, but such is life hehe

This entry was posted in General, lartens, programming. Bookmark the permalink.

Recent Posts

Leave a Reply

Your email address will not be published. Required fields are marked *