1
0
mirror of https://github.com/mbirth/wiki.git synced 2024-12-25 23:04:06 +00:00
wiki.mbirth.de/software/autohotkey/_posts/2009-09-12-u3helper.md

6.5 KiB

title language layout created updated toc tags
U3Helper en default 2009-02-28 02:26:46 +0100 2009-09-12 01:38:44 +0200 false
software
autohotkey
u3helper

Preface

Being proud owner of a [U3 capable]({% post_url 2011-07-22-u3 %}) flash drive, I wanted to add some of the tools I use everyday but which were not U3 compatible.

Running a U3 program from the LaunchPad basically does the following things:

  1. unpack the .u3p package (which is a .zip) to your local Application Data\U3 directory
  2. run the hostConfigure command from the manifest file (once per session)
  3. run the appStart command from the manifest file (this starts the application)

Ejecting the U3 drive does the following for all programs which were ran in that session:

  1. if the program is still running, run the appStop command from the manifest file
  2. run the hostCleanUp command from the manifest file

Most programs store their settings in a key in the Windows registry. Some others need an .ini file in their folder. So in both cases it's relatively easy to move them to another location and run them from there.

After I had successful runs using a batch file for hostConfigure which imported a registry file and another batch file for hostCleanUp which exported the new settings to that file, I wanted to create a tool which automates most steps neccessary for a program to run.

So the U3Helper was born.

The first version got too complicated after a while and so I started from scratch. The result it this tool.

Usage

This manual assumes you already know which registry branches and/or configuration files and/or OCXes/DLLs your application uses.

Manifest file

Make the actions-section of your manifest.u3i look like this (the parameters in the appStart tag are for WebMon, not for the U3Helper):

{% highlight xml %} config -prefs "%U3_APP_DATA_PATH%\WebMon.ini" -pages "%U3_APP_DATA_PATH%\pages\WebPages.dat" appstop unconfig {% endhighlight %}

Note: The GUID `0f90f88c-5e05-4cab-8c3a-e1c0112b06fd` is that of the U3Helper, NOT the one of the application of that manifest!

If the application writes something to %USERPROFILE%\Application Data, change the appStart line to look like this:

<appStart cmd="%U3_HOST_EXEC_PATH%\U3Helper.exe">appstart</appStart>

This way, the U3Helper will change some environment variables for the launched application so that it stores all user-data on the flash drive instead of on the local harddisk.

U3Helper.ini

Now create a file U3Helper.ini and put it into the host directory in your U3 package so that it gets extracted to %U3_HOST_EXEC_PATH%.

Here is a template:

{% highlight ini %} [U3Helper] AppName=PC OnPoint AppExe=PConPoint.exe

; enter commandlines to run before stopping the application and before ; ejecting the device. All variables mentioned under [FileDelete] work. RunBeforeStop= RunBeforeEject=

; set Unattended to 1 to suppress settings-related questions ; this way, previously existing settings on the host always get ; replaced by the U3's settings and restored on eject Unattended=0

[RegBackup] ; enter registry branches to be backed up (+deleted) on eject ; and restored on first run ; SHORTCUTS (HKCU, HKLM,...) DON'T WORK! HKEY_CURRENT_USER\Software\PC OnPoint

[RegDelete] ; enter registry branches to be just deleted without backup

[regsvr32] ; enter filenames to be registered using regsvr32 ; these files are assumed to be in %U3_HOST_EXEC_PATH% CCListBar.ocx

[DataToExecDir] ; enter filenames or foldernames to be copied to the %U3_HOST_EXEC_PATH% ; and copied back to %U3_APP_DATA_PATH% afterwards ; ONLY SIMPLE NAMES, NO PATHS OR WHATSOEVER! safe.dat safe.ind

[ParseIniFiles] ; enter filenames of .ini-files to be parsed for env vars on hostConfigure ; and re-replace the paths by envvars on hostCleanUp. The files should reside ; in %U3_APP_DATA_PATH% test.ini

[FileDelete] ; enter filenames or foldernames to be deleted on eject ; Environment variables working (case sensitive!): ; %ALLUSERSPROFILE%, %APPDATA%, %CommonProgramFiles%, %HOMEPATH%, ; %ProgramFiles%, %SystemRoot%, %TEMP%, %USERPROFILE%, %WINDIR%, ; %U3_APP_DATA_PATH%, %U3_DEVICE_DOCUMENT_PATH%, %U3_DEVICE_EXEC_PATH% %ALLUSERSPROFILE%\Application Data\Spybot - Search & Destroy

[EnvPath] ; enter folders to be added to the PATH environment variable ; upon running the application. All variables mentioned under ; [FileDelete] get replaced. %U3_HOST_EXEC_PATH%\lib\gtk\bin {% endhighlight %}

  • All registry keys listed under [RegBackup] are being backed up on eject of the U3-stick to sequential files (regdata1.reg, regdata2.reg and so on) in %U3_APP_DATA_PATH% and afterwards, the keys are deleted from the host machine. Also those branches are inserted back into the registry upon the first launch of that app after plugging in the stick.
    • if you put a file regdataX.reg into the data directory in your U3 package, this file gets imported into the registry after all other files have been processed. But this file never gets overwritten by a newer dump so it's perfectly to enforce some settings the program changes every time, like relative paths into absolute paths.
    • The section [RegDelete] just deletes those keys upon eject.
    • Under [regsvr32] you can list all .ocx or .dll files which should be registered before launching the app and unregistered on eject. The files are assumed to be in %U3_HOST_EXEC_PATH%.
    • Finally [DataToExecDir] lists files which should be copied into the directory containing the application (many applications insist on their config-files lying where the .exe lies) and back to %U3_APP_DATA_PATH% on eject.

Download

  • [u3helper.zip]({{ site.url }}/assets/u3helper.zip) version 2.1, April 2007, incl. sources
  • [u3helper.u3p]({{ site.url }}/assets/u3helper.u3p) version 2.4, June 2008

See also

    {% for page in site.categories.u3helper %}
  • {{ page.title }}{% if page.language == 'de' %} (German){% endif %}
  • {% endfor %}