Install Windows 7 from USB Thumb Drive

The Windows 7 USB/DVD Download Tool can copy a Windows .ISO file to a USB thumb/pen drive.

Posted in Technology, Windows | Leave a comment

Windows Vista/7 File System Virtualization

Along with User Account Control, Windows Vista and Windows 7 use file system and registry virtualization to improve compatibility with applications which break Windows development security guidelines. If an application attempts to write to a disallowed location (such as the root directory, or Program Files), the file is silently relocated under %localappdata%/VirtualStore.

So, if you’re running an older application and you can’t figure out where it stored its files (e.g. DVD Decrypter, as in my case), look under:

C:\Users\username\AppData\Local\VirtualStore

This MSDN page has an excellent summary of file and registry virtualization (search the page for “virtualization”).

Posted in Technology, Windows | Leave a comment

Cygwin: No Output from Rsync

I experienced a very strange situation where rsync simply stopped working. It wouldn’t even output anything for rsync --help or even plain rsync. which showed it to be in /usr/bin/rsync as expected. A closer look revealed something odd:

$ ls -lah /usr/bin/rs*
-rwxr-xr-x 1 fitzsimj None    0 2010-01-11 13:40 /usr/bin/rsync
-rwxr-xr-x 1 fitzsimj root 349K 2010-02-19 11:20 /usr/bin/rsync.exe

I had a mysterious, empty rsync file next to rsync.exe in my /usr/bin folder. Deleting the rsync file fixed my problem. I have no idea where this came from.

Posted in Cygwin, Technology | Leave a comment

Fixing Camcorder IEEE 1394/Firewire Connection Problems on Windows 7

I’m running Windows 7 Home Premium 64-bit on my Toshiba A505 Satellite, which has a Firewire port. If I connected my Sony camcorder (DCR-HC40) I would just get either an endless connect/disconnect cycle, or simply nothing at all. Firewire just did not appear to work.

The solution was to roll the IEEE 1394 (“Firewire”) Bus Host Controller driver back to the legacy version. It’s detailed in this Technet post. The important steps are:

  1. Click the Start Button, type devmgmt.msc in the “Start Search” box and press Enter.
  2. Expand the “IEEE 1394 Bus Host Controllers” node in the device tree on the right hand pane
  3. Right click the host controller node select “Update driver software …”
  4. Select “Browse my computer for driver software”
  5. Select “let me pick from a list of device driver on my computer …” and Check the box before “Show compatible hardware”.
  6. Choose the second option—1394 OHCI Compliant Host Controller (Legacy), and click next to update the driver.

Posted in Technology, Windows | Leave a comment

IME Functions Fail From Separate Process

I wanted to change the behavior of the Microsoft IME bar using AutoHotkeys, a utility which can be used to create macros, remap keys, or do any of a variety of other related tasks.

This led me to ime_func.ahk, which appears to be an AutoHotkeys script which uses DllCall to access Imm32.dll, the Input Method Manager library. I believe that this script was intended to manipulate the state of the IME language bar.

As near as I can tell, this AutoHotkeys script targets an older implementation of the IMM library. Some of the methods used are now only listed for Windows Mobile platforms.

I began experimenting with ImmGetContext and ImmGetConversionStatus. ImmGetContext always returned a hIMC value of NULL.

On the Developing IME-Aware Multiple-thread Applications MSDN page, the following is stated (bold highlight added):

The IMM includes thread identification checking that determines if a calling thread is the creator of a specified input method context handle (HIMC type) or window handle (HWND type). If the thread is not the creator of the handle, the called IMM function fails and a subsequent call to GetLastError returns ERROR_INVALID_ACCESS.

Additionally:

  • A thread should not access the input context created by another thread.

  • A thread should not associate an input context with a window created by another thread, and vice versa.

So, it appears that cross-process IME manipulation is forbidden.

Posted in Technology, Windows | 1 Comment

GnuPG Not Working Under Cygwin

I was having trouble using the GnuPG plugin for vim under Cygwin. The GnuPG plugin allows seamlessly integrated decryption, editing, and re-encryption of GPG-encrypted content within vim. However, on my Windows 7 box, it just showed gibberish. Attempting to edit my encrypted password file resulted in a rather vague error message:

$ vim Documents/passwords.gpg

"Documents/passwords.gpg" [Incomplete last line][converted] 7 lines,
2547 characters
Press ENTER or type command to continue

Pressing enter simply resulted in gibberish, likely the raw data of the encrypted file.

The solution was to turn on vim’s filetype plugin processing:

:filetype plugin on

To make this setting persistent, add it to your ~/.vimrc file.

Posted in Technology, Windows | Leave a comment

Converting MP3 to AAC

Here is a Windows command shell script I wrote to convert MP3 files to AAC for my Softbank 821SC phone. The script uses FFmpeg, which I downloaded from here.

@echo off

REM ---------------------------------------------------------------------------
REM  Set the following variable to the ffmpeg.exe path on your system.
REM ---------------------------------------------------------------------------
set FFMPEG_PATH="c:\tools\FFmpeg\ffmpeg.exe"

REM make sure the user provided an argument.
if NOT "%~1" == "" goto ARGS_OK

REM bad arguments, print error and exit.
echo.
echo    Usage examples:
echo       mp3toaac.bat file_to_convert.mp3
echo       mp3toaac.bat *.mp3
echo       mp3toaac.bat some_directory\*.mp3
exit /b 1

:ARGS_OK

REM use for/in so that we can accept individual files or wildcards.
for %%i in ("%~1") do %FFMPEG_PATH% -i "%%~i" "%%~ni.aac"

echo.
echo Done.

exit /b 0

Interesting elements of this batch file:

  • Use of for/in in order to accept both filenames and wildcards.
  • Use of %~X to strip parentheses from a filename variable.
  • Use of %~nX to strip the extension from a filename variable (i.e. retrieve the basename).
Posted in Scripting, Technology, Windows | Leave a comment

SSH Tunneling Windows RDC

This article explains how to securely port-forward Windows Remote Desktop (Terminal Services) over SSH, using standard SSH command line syntax. If you prefer to use GUI SSH tools, such as PuTTY, there are other guides for that.

Terminology Notes

My terminology assumes that you are connecting to a machine on your home network, which is protected by a firewall. However, the diagrams and commands are valid regardless of whether the remote network is at home or not.

Additionally, I use RDCHOST to represent the local name or IP of your RDC server within the home network, and my_home_ip to represent your home IP address as visible from the Internet.

Prerequisites

  • Depending on network configuration, port-forwarding may have to be configured on the firewall.
  • An SSH client (e.g. Cygwin’s OpenSSH for Windows) must be installed on the local machine.
  • An SSH server (e.g. Cygwin’s OpenSSHD for Windows) must be present on some machine within the home network.
  • SSH keys must be generated and deployed appropriately.

SSH Command Syntax

ssh -C -N -L localPort:destinationHost:3389 proxyHost

  • localPort is the port on localhost through which you wish to connect.
  • destinationHost is the Remote Desktop host, as it appears on the home network.
  • proxyHost is the host running SSHD, through which you will tunnel.

Configuration 1: Discrete Servers

This configuration has the firewall port-forward SSH to a server on the home network, which proxies the connection to the RDC server:

                       +-----------[ Home Network ]---------------+
                       |                                          |
localhost <----> Home Firewall <---> SSH Server <---> RDC Server  |
                       |                                          |
                       +------------------------------------------+

Command line:

ssh -C -N -L 6009:RDCHOST:3389 my_home_ip

Configuration 2: Combined RDC & SSH Servers

In this configuration, the RDC server also has an SSH server, and the firewall port-forwards directly to it:

                       +------[ Home Network ]-----+
                       |                           |
localhost <----> Home Firewall <-----> RDC & SSH   |
                       |                Server     |
                       +---------------------------+

Command line:

ssh -C -N -L 6009:localhost:3389 my_home_ip

Configuration 3: Firewall as SSH Server

In this configuration, the firewall acts as the SSH server, proxying the connection directly to the RDC server on the home network:

                       +----[ Home Network ]----+
                       |                        |
localhost <----> Home Firewall <---> RDC Server |
                  & SSH Server                  |
                       |                        |
                       +------------------------+

Command line:

ssh -C -N -L 6009:RDCHOST:3389 my_home_ip

Additional Suggestions

Rather than specifying the IP address of your home firewall, I suggest using DynDNS to get a dynamic DNS entry.

Posted in Linux, Scripting, Technology, Windows | Leave a comment

CoCreateInstance Fails With “Class Not Registered”

Recently, I had a problem unique to my test machine. Attempting to call CoCreateInstance on a COM class provided by one of our DLLs resulted in HRESULT 0×80040154, which corresponds to “Class not registered”.

This was a mystery since regsvr32 appeared to properly register our DLL, and all the obvious registry keys were intact!

After a bit of web searching, I experimented with using CLSCTX_ALL instead of CLSCTX_INPROC_SERVER. Now, the call succeeded! But why, since this is a DLL and, therefore, should be considered an in-process COM server?

MSDN documentation states that CLSCTX_ALL is defined as the combination of CLSCTX_INPROC_SERVER, CLSCTX_INPROC_HANDLER, and CLSCTX_LOCAL_SERVER. I began substituting each one in turn and found that the key was CLSCTX_LOCAL_SERVER.

Stepping through the code in the debugger revealed that the instant the CoCreateInstance call was made, a new instance of dllhost.exe appeared in the process list. This explained why CLSCTX_INPROC_SERVER would fail, since strictly speaking, the DLL was being hosted in dllhost’s process space.

Ultimately, the problem turned out to be an artifact from an old COM+ experiment. There was a COM+ entry corresponding to our COM server in the Component Services panel (Control Panel | Administrative Tools | Component Services, under Component Services | Computers | My Computer | COM+ Applications). The COM+ entry dictated that the COM server be hosted by proxy by dllhost.exe. Deleting this COM+ entry and re-running regsvr32 fixed the problem.

Component Services panel in Administrative Tools

Posted in COM, Technology, Win32, Windows | Leave a comment