Generate Autorun.inf on Windows and Linux easily

Nowadays, PC game updates are often huge. They can range from less than 10 MB to gigabytes now. I burn these as I consider them game upgrades nearly. The thing is I do not feel like browsing to the setup executable every time I use the disc. So I generate an Autorun.inf file. Of course this is useful for anything that you need burned to disc that needs to launch an application (like a setup) on insertion (often used for picture CDs, etc).

The Windows Autorun.inf file has become standard since Windows 95 for doing anything from simply running an application or command to adding new context menu items to the drive letter (shell menu options), upon inserting a disc. Wikipedia has this all well documented at its Autorun.inf article.

I only need to launch the setup of the update. And I would not mind having an icon too just to make things pretty.

For Linux:

Yes I know it might be surprising, but even us Linux users run games and need our up-to-date patches. Note that of course Autorun.inf is useless in most cases (I have not even seen a KDE or GNOME extension to allow Wine to run the executable). Maybe it is because of the security of Autoplay in general. Even though it's Wine, I still do not want an auto-playing executable to destroy my Wine prefix.

To generate the Autorun.inf file, determine the executable that needs to be run. Test it in Wine or a virtual machine. I suggest attempting to extract the executable if it is a huge one (more than 20 MB). Often then the file to run becomes setup.exe or something similar. It might be MSI file, in which case you will want to use msiexec /i >MSI file< as your command to run on insertion.

Before running this script, always cd into the directory you will be generating the Autorun.inf file.

Then, with autorungen (or whatever you wish to call it) in $PATH (view your $PATH by typing echo $PATH), run autorungen setup.exe setup.exe 0. The first argument is the executable file (or batch file) to run on insertion. The second is the icon (this could be an EXE, DLL, or ICO file). The last argument is the index, where 0 is the first icon (the one that you will see in Explorer). There are plenty of tools out there to help you see all the resources in a file.

#!/bin/sh
# autorungen

function usage {
  echo "Usage: $0 <exe file> <icon> <icon index>"
}

if [ "$1" = "" ]; then
  usage
elif [ "$2" = "" ]; then
  usage
elif [ "$3" = "" ]; then
  usage
else
  EXE="$1"
  ICO="$2"
  ICO_INDEX="$3"

  printf "[Autorun]\nopen=$EXE\nicon=$EXE,$ICO_INDEX\n" >> Autorun.inf
  unix2dos Autorun.inf
fi

Just for safety, the script makes sure the line endings are CR+LF, Windows format. I know Autorun.inf files work (most Linux distro discs that include something to run on Windows do not convert their Autorun.inf files to CR+LF) as UNIX encoded, since the Windows API puts(), gets(), scanf(), etc functions are line-ending format independent just like POSIX and GNU standard C.

This should also work for Mac OS X.

For Windows:

This is a batch file. Save it to autorungen.bat or whatever you wish to call it and place it somewhere in %PATH%. You can see your system variables by:

Windows 2000 and XP

  1. Right-click Computer or My Computer and choose Properties.
  2. Click the Advanced tab.
  3. At the bottom, click the Environment variables button. Here you may configure %PATH% and all the other user and system (global) variables.

Windows Vista and 7
To be added soon...

For example: My system %PATH% is very long:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\GNU\bin;C:\Program Files\GNU\bin\dll;C:\Program Files\Utils;C:\Program Files\SlikSvn\bin\;C:\Program Files\MiKTeX\miktex\bin;C:\Program Files\Aspell\bin;C:\Program Files\Notepad++;C:\Program Files\GNU\contrib\chess-5.07-bin;C:\Program Files\GNU\lib\gettext;C:\Program Files\GNU\libexec;C:\Program Files\GNU\libexec\ttf2pt1;C:\Program Files\GNU\sbin;C:\WEP;C:\msys\1.0\bin;C:\Program Files\ImageMagick;C:\Program Files\Vim\vim72;C:\Qt\bin;C:\MinGW\bin;C:\Qt\qt\bin;C:\Program Files\Sun\VirtualBox;C:\Program Files\WinHex;C:\Program Files\WinHTTrack;C:\Program Files\Vim\vim72

This is because I tend to use cmd and MSYS a lot on Windows day-to-day. I cannot live without command line after using Linux for so long. So you can see the format is C:\Dir1;D:\Dir2 (there is a reason why a Windows file cannot have a ; symbol in it). So I place autorungen.bat in C:\Program Files\Utils, a directory full of my personal utilities I find extremely useful.

If you want to be ultra lazy, just put autorungen.bat in your WINDOWS (%SYSTEMROOT%) or system32 directory.

@echo OFF
REM autorungen.bat

if %3.==. goto USAGE
echo [Autorun] >> Autorun.inf
echo open=%1 >> Autorun.inf
echo icon=%2,%3 >> Autorun.inf
goto :DONE

:USAGE
echo Usage: %0 ^<exe^> ^<icon^> ^<icon index #^>
echo Example: %0 setup.exe icon.ico 0"

echo
echo Will generate an Autorun.inf in the current directory.

:DONE

Now run cmd (Start menu->Run), cd to the directory that needs an autorun.inf and use the autorungen command: autorungen setup.exe setup.ico 0, where setup.exe is the application to run, setup.ico is the icon to use, and 0 is the icon index within the icon or icon resources of the file. Again there are many applications out there to see what resources are inside files for Windows. Sometimes you may not be able to view them or extract them due to unknown compression. Not everyone is using upx afterall.

My own batch file is different, as it uses printf from the GNUWin32 project.

@echo off

REM Original script
REM #!/bin/bash
REM if [ "$3" = "" ]; then
REM   echo "Usage: $0 <exe> <icon> <icon index #>"
REM   echo "Example: $0 setup.exe icon.ico 0"
REM   printf "\nWill generate an Autorun.inf in the current directory.\n"
REM else
REM   printf "[Autorun]\nopen=$1\nicon=$2,$3\n" >> Autorun.inf
REM   unix2dos Autorun.inf > /dev/null
REM fi

if %3.==. goto USAGE
printf "[Autorun]\nopen=%1\nicon=%2,%3\n" >> Autorun.inf
goto :DONE

:USAGE
echo Usage: %0 ^<exe^> ^<icon^> ^<icon index #^>
echo Example: %0 setup.exe icon.ico 0"

printf "\nWill generate an Autorun.inf in the current directory.\n\n"

:DONE

GnuWin32, for the betterment of Windows If you are a dual-booter with Windows but use Linux most of the time like me, I strongly suggest trying the GnuWin32 tools out. If you hate the syntax of copy vs cp for special operations, or you hate how there's no printf command line application on Windows, or more reasons to hate Windows, get the tools. Unlike Cygwin, they can be made available to be seen in cmd and they work fine with MSYS. However, some tools available to Cygwin are not available at all in GnuWin32 or MSYS.

Completing the process

Now burn your disc with any tool (K3b, Nero, ImgBurn, etc), making sure that the generated Autorun.inf file is at the root of the disc or it will not work. After the burn, insert a Windows machine (or mount into a Windows VM), and voila.

I would strongly suggest testing before burning. Generate an ISO and mount and see if everything works properly.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Syntax highlight code surrounded by the {syntaxhighlighter OPTIONS}...{/syntaxhighlighter} tags.
  • HTML tags will be transformed to conform to HTML standards.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.