Thursday, June 23, 2011

Forward ports via USB to Android devices automatic on connection

You can use USB Autorun to forward local ports to the android device which is connected via USB. This is handy if you don't have a WiFi or need more constant transfer rates (could be faster also).
It's very handy if you need to use Applications like via USB:

Remote Web Desktop: Market URL
LazyDroid Web Desktop: Market URL
PAW Server for Android: Market URL
and many other web server based application.

There are some initial steps, but when it is set up it's easy to use.


  1. Download and install Android USB drivers: http://developer.android.com/sdk/win-usb.html you have to install the Android SDK and install it from there. If your Android device need OEM USB drivers like Motorola, HTC and more, then you have to install them as well.
  2. Enable USB debugging on your Android device (Settings->Applications->Development->USB debugging)
  3. Make sure that the adb.exe file path is accessible from all over you system by adding the path to the System Variables PATH: (possible path C:\Android\tools)

    1.        For Windows XP:
    1.        Start -> Control Panel -> System -> Advanced
    2.        Click on Environment Variables, under System Variables, find PATH, and click on it.
    3.        In the Edit windows, modify PATH by adding the location of the adb.exe to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
    4.        Close the window.

    For Windows Vista/7:
    1.        Right click “My Computer” icon
    2.        Choose “Properties” from context menu
    3.        Click “Advanced” tab (“Advanced system settings” link in Vista/7) -> Environment Variables
    4.        In the Edit windows under System variables, modify PATH by adding the location of the adb.exe to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
    5.       Close the window.

  4. Download USB Autorun from here: http://helioxware.blogspot.com/p/usb-autorun.html
  5. Download this bat-file http://dl.dropbox.com/u/4213200/USBAutorun/autorun.bat and edit the port 8080 to the port you need to forward (multiple forward lines can be added).
  6. Run USB Autorun and open it from the taskbar.
  7. Click USB Devices -> Select USB Device and find you connected Android USB device. Double click on the text and select the downloaded and edited bat-file from step 5.
  8. Disconnect and connect you Android device and see the log (main window) in USB Autorun.
  9. If the log print "File has been executed: [bat-file-path] then USB Autorun is working. DONE!
  10. You can add USB Autorun to the startup menu if you like! (I just have all needed files in my dropbox folder for easy sync on all by computers).
Tips and Troubleshooting

  • You can still edit the bat-file and the reconnect the Android device which updated the new forwards.
  • You can have multiple Android devices to the same bat-file or have separate bat-files for each Android device.
  • Any executable file can be run in USB Autorun
  • To test adb.exe and the Android USB drivers are working you can connect you Android device. Start a command prompt (cmd) and change directory into the Android SDK (to eliminate the PATH environment varibles are not working) and into the tools folder (possible path C:\Android\tools) where the adb.exe should be found. Write "adb devices" [Enter] and expect a list of connected Android devices with device numbers. If this is not working it could be that OEM USB drivers should be installed or the USB cable is not made for data transfer (only change).
  • You can add a line at the end of the bat-file "pause" and run it manually, to see errors if any.