Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

U3Helper: Make almost any application U3 Smart capable


  • Please log in to reply
29 replies to this topic
mbirth
  • Members
  • 40 posts
  • Last active: Jul 31 2008 11:12 AM
  • Joined: 03 Oct 2005
I bet at least some of you already heard of these new USB Flash sticks with U3-functionality? There you can install applications which run on any Windows-PC you put the stick in and after removing the stick, all traces are removed as if you were never there. So you can have all your lovely tools with you.

Usually developers have to take care, their apps are U3-compatible, don't write anything to the registry, run without installation of some drivers, etc. pp. So the selection of U3-applications is rather small and it's taking ages for new apps to get released.

I already tried to make a script which takes care of registry entries, registration of .ocx/.dll files and movement of configuration files but this former project got too complicated and I stopped developing it. Now I wrote such thing from scratch in about 4 evenings. You configure it via an INI-file. But first the script:

Source code and compiled U3-Package can be downloaded here. (243 kB, Mirror)
[BugTracker]
[Forum]

To download various applications I converted to U3 using my U3Helper, go there:
[U3 Download area]


You just have to make the action-section of your manifest.u3i look like this:

<actions>
    <hostConfigure cmd="%U3_DEVICE_EXEC_PATH%\..\..\0f90f88c-5e05-4cab-8c3a-e1c0112b06fd\Exec\U3Helper.exe">config</hostConfigure>
    <appStart workingdir="%U3_APP_DATA_PATH%" cmd="%U3_HOST_EXEC_PATH%\WebMon.exe">-prefs "%U3_APP_DATA_PATH%\WebMon.ini" -pages "%U3_APP_DATA_PATH%\pages\WebPages.dat"</appStart>
    <appStop cmd="%U3_HOST_EXEC_PATH%\U3Helper.exe">appstop</appStop>
    <hostCleanUp cmd="%U3_HOST_EXEC_PATH%\U3Helper.exe">unconfig</hostCleanUp>
  </actions>

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

Now, create an U3Helper.ini and put it in the "host"-directory inside the U3-package, so that it gets into %U3_HOST_EXEC_PATH%. The INI may look like this:

[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

And finally install the U3Helper.u3p to your U3 device. Note: The usual way of putting the U3Helper.exe into the "host"-directory of a U3-package still works. Just set the manifest.u3i correctly!


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.

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.


Using this helper script, you can get almost any application U3-smart. The most tricky part is to get the used registry branches and sometimes it's hard to find all needed OCXes for one program to work.


Hope here's at least one U3-developer who might find this useful. :-) I already "ported" CCleaner, CDBurnerXP, DeepBurner, EVEREST, Handy Safe, Media Player Classic, MWAV Toolkit, Notepad++, OffByOne, PC OnPoint, SmartFTP, TrueCrypt, UltraISO and WebMon. All these apps are now available on whatever Windows-PC I plug my U3-stick into - with my personal settings.



Cheers,
-mARKUS


P.S.: There's something I needed for CDBurnerXP: If you put a file regdataX.reg to %U3_APP_DATA_PATH% it is inserted into the registry after all other data has been inserted. CDBurnerXP set its paths to absolute paths in its registry settings and I had to find a way to reset them to U3-specific paths.

P.P.S.: Please, if you made any app U3-capable, Upload it to my FTP at ftp://riddick.is-a-geek.net/ . This FTP is not always available, so if it is down, try again some hours/days later. There are also many U3-Apps, I already converted.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
This sounds really interesting! Thanks for sharing it!

Could you give some U3 introduction for us, dummies? What do we have to do to prepare an application to run from the U3 stick? Install it on the stick plugged in any PC, compare the host registry before and after and add the changes to our ini file? Cannot we use regular USB disks, with a simple script to launch the application with first setting up the registry and cleaning it up at the end? What happens if the user removes the USB disk before it could clean up the registry? (Is there a cleanup mode?) What if the application or the PC crashes?

mbirth
  • Members
  • 40 posts
  • Last active: Jul 31 2008 11:12 AM
  • Joined: 03 Oct 2005

Could you give some U3 introduction for us, dummies? What do we have to do to prepare an application to run from the U3 stick?


U3 mainly consists of some guidelines like "don't write anything to the registry", "only use the specified folders on the stick", etc. ... all specific U3-paths are made available through environment variables, so that an app can easily know where to store everything. An U3-package is just an ordinary .zip-file with 3 or 4 directories in it. One of it, the "host" directory, gets unpacked to the host PC and should contain the main executable which is then run. On clicking "eject" in the U3-LaunchPad (sth. like a START-menu for all installed U3-applications on the stick), these files are removed from the host PC so the app must keep its settings directly on the stick in a special data area.

Visit www.u3.com for more info.


Install it on the stick plugged in any PC, compare the host registry before and after and add the changes to our ini file?


This would be too slow. Comparing the registry takes ages. Instead you have to specifiy the registry branches which are used by the app.


Cannot we use regular USB disks, with a simple script to launch the application with first setting up the registry and cleaning it up at the end?


I might implement a "non-U3"-way into my app some day. Shouldn't be very complicated and you usually don't have to move data files then.

What happens if the user removes the USB disk before it could clean up the registry? (Is there a cleanup mode?) What if the application or the PC crashes?


If you remove the stick, the cleanup still works, because all neccessary files are kept on the host PC. On removing the stick, the LaunchPad automatically calls all cleanup stuff. Only drawback is, that your changed settings or these apps are not saved.

If the app crashes, the LaunchPad is still running and cleanup will work fine. If your PC crashes, you have to manually clean the settings from the registry because my script won't delete registry settings if they were already on the host PC.

Cheers,
-mARKUS

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Thanks! I often have to clean up the mess in my family members' PCs, and now I can put the necessary tools on a USB disk. I used tools CDs, which I had to re-burn each time a new version of a tool appears. On the USB disk I just update the files. Cool!

jack_brody
  • Members
  • 2 posts
  • Last active: Mar 16 2007 08:32 AM
  • Joined: 16 Mar 2007
Mbirth,

which environment variables U3 provides and how can they be retrieved? I need to set up a .cmd script which will copy some files from the U3 flash disk to harddrive. But the flash disk may get different letters on various systems, so I cannot use absolute paths for the source of the files. Are there some variables like %SYSTEMROOT% or %APPDATA%, but for paths on U3 disk?

I think this is a task which thousands of people are trying to solve every day, and I am suprised I cannot find any info on how to do it.

Thank you

mbirth
  • Members
  • 40 posts
  • Last active: Jul 31 2008 11:12 AM
  • Joined: 03 Oct 2005

Are there some variables like %SYSTEMROOT% or %APPDATA%, but for paths on U3 disk?


Indeed, there are! You can read about them in the U3 SDK.

EnvGet U3_DEVICE_SERIAL, U3_DEVICE_SERIAL                    ; serial number of device (copy protection)
EnvGet U3_DEVICE_PATH, U3_DEVICE_PATH                        ; drive letter to device (F:)
EnvGet U3_DEVICE_DOCUMENT_PATH, U3_DEVICE_DOCUMENT_PATH      ; path to documents (F:\Documents)
EnvGet U3_DEVICE_VENDOR, U3_DEVICE_VENDOR                    ; vendor
EnvGet U3_DEVICE_PRODUCT, U3_DEVICE_PRODUCT                  ; product name string
EnvGet U3_DEVICE_VENDOR_ID, U3_DEVICE_VENDOR_ID              ; vendor id (decimal!! 2284 = 0x08ec)
EnvGet U3_APP_DATA_PATH, U3_APP_DATA_PATH                    ; data path for app (on device)
EnvGet U3_HOST_EXEC_PATH, U3_HOST_EXEC_PATH                  ; path to exe on host
EnvGet U3_DEVICE_EXEC_PATH, U3_DEVICE_EXEC_PATH              ; path to needed files on device
EnvGet U3_ENV_VERSION, U3_ENV_VERSION                        ; should be 1.0
EnvGet U3_ENV_LANGUAGE, U3_ENV_LANGUAGE                      ; language id of LaunchPad
EnvGet U3_IS_UPGRADE, U3_IS_UPGRADE                          ; can be "false" or "true"
EnvGet U3_IS_DEVICE_AVAILABLE, U3_IS_DEVICE_AVAILABLE        ; "true"/"false"
EnvGet U3_IS_AUTORUN, U3_IS_AUTORUN                          ; is this an autorun-launch? "true"/"false"
EnvGet U3_DAPI_CONNECT_STRING, U3_DAPI_CONNECT_STRING        ; who needs this?

Remarks:
%U3_APP_DATA_PATH% is somewhere like F:\System\Apps\0DE4F643-C398-46ec-9339-2362F2311932\Data\
%U3_DEVICE_EXEC_PATH% is the same with ...\Exec\ instead of \Data\.
%U3_HOST_EXEC_PATH% is somewhere on C:\Documents and Settings\username\Application Data\U3\0DE4F643-C398-46ec-9339-2362F2311932\Exec\ .



But here comes the big BUT: They are only set when some app (or script) is launched via the U3 LaunchPad. So you should make an U3-Package out of your script to get this to work.

Cheers,
-mARKUS

jack_brody
  • Members
  • 2 posts
  • Last active: Mar 16 2007 08:32 AM
  • Joined: 16 Mar 2007
Mbirth,
thank you very much, these variables are readable by my script, it is working great! :-)
Have a nice day

Jack

mbirth
  • Members
  • 40 posts
  • Last active: Jul 31 2008 11:12 AM
  • Joined: 03 Oct 2005
There were some additions since my initial post ... so here they come.

The U3Helper.ini now supports following things:
[U3Helper]
AppName=PC OnPoint
AppExe=PConPoint.exe
; 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

[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

Changelog reads like this (but there are missing older changes):

Revision: 722
Author: mbirth
Date: 2007-03-21 10:56:23
Message:
* modularized U3Helper.ahk
+ added take-over of icon of %AppExe% ... if we add a TrayIcon someday
+ added OnClose-handling when using appstart (kills process of main application)
----
Added : /AutoHotKey/U3Helper/trunk/U3H_appStart.ahk
Added : /AutoHotKey/U3Helper/trunk/U3H_appStop.ahk
Added : /AutoHotKey/U3Helper/trunk/U3H_hostCleanUp.ahk
Added : /AutoHotKey/U3Helper/trunk/U3H_hostConfigure.ahk
Modified : /AutoHotKey/U3Helper/trunk/U3Helper.ahk


Revision: 721
Author: mbirth
Date: 2007-03-21 08:18:27
Message:
+ hostCleanUp: check whether datafile is still existing in program-folder and delete in %U3_APP_DATA_PATH% if not
----
Modified : /AutoHotKey/U3Helper/trunk/U3Helper.ahk


Revision: 720
Author: mbirth
Date: 2007-03-14 00:34:47
Message:
+ specify paths to add to local PATH variable
+ show version number
+ hostCleanUp: "Cancel"-button to erase registry settings if there were some upon launch (if LaunchPad didn't shutdown correctly and registry settings were left)
x Unattended-switch didn't do cleanup of registry and regsvr32
----
Modified : /AutoHotKey/U3Helper/trunk/U3Helper.ahk
Modified : /AutoHotKey/U3Helper/trunk/U3Helperex.ini


I've updated the download file (230,3KiB) and also added a forum to discuss the U3Helper and how to convert apps to U3.

See: http://vanilla.birth-online.de/3/

A list of already-converted applications is on my personal blog here (German language, sorry).

You can download them from my FTP here. Note: These files are hosted on my PC at home, so whem I'm offline or need more bandwidth (it's just DSL2000/208), the FTP is offline. Just try at different times/days. Oh, and don't leech or you'll get banned.

You are also encouraged to upload applications you have converted using U3Helper.


Cheers,
-mARKUS

n-l-i-d
  • Guests
  • Last active:
  • Joined: --
Very interesting.

The most tricky part is to get the used registry branches


I don't know how speedy an AHK script would be to do a registry compare, but you might consider including RegShot to do this, it's tiny (~50k executable), and open source.

Regshot is a small,free and open-sourced registry compare utility that allows you to quickly take a snapshot of your registry and then compare it with a second one - done after doing system changes or installing a new software product. The changes report can be produced in text or HTML format and contains a list of all modifications that have taken place between snapshot1 and snapshot2. In addition, you can also specify folders (with sub filders) to be scanned for changes as well.



mbirth
  • Members
  • 40 posts
  • Last active: Jul 31 2008 11:12 AM
  • Joined: 03 Oct 2005
The thing is: Windows is constantly changing values in the registry so doing a registry-compare and removing all changes could make your whole computer unusable afterwards because essential values may get replaced by old data.

So the easiest way is to monitor an application using Process Monitor (or separate Filemon and Regmon) and write down those paths under HKCU\Software and HKLM\Software belonging to the application. They are mostly HKCU\Software\ or something like HKLM\Software\ .


Cheers,
-mARKUS

n-l-i-d
  • Guests
  • Last active:
  • Joined: --
Sure, but you could include RegShot, and exclude the registry entries that are not related from the search with the regshot.ini file. You could present the result in AHK, and let the user filter out the errors. I assumed you wanted to create a helper, and if you already assume the user knows how to use Filemon or Regmon or others, you don't need a helper no more.

It is always hard to find exactly what the application does and ofcourse you have to make sure you don't remove any wrong files or registry entries afterwards. You can however atleast find many changes to your system with RegShot and you could include it in your distribution. If you automate it fully, like add an optional System Restore point before, auto-install the application, maybe even auto-use the program to detect changes, than you could use RegShot (or better: AutoHotkey) to find the changes. Like Total Uninstaller. Let me suggest AutoAppAnalyseAndConvertForU3AndPortables :p

Oh, I don't have a U3 disk, and I guess there are many like me, but I do have a portable USB disk, and application portability is a much requested topic, why not extend it to support that too? Just thoughts. 8)

mbirth
  • Members
  • 40 posts
  • Last active: Jul 31 2008 11:12 AM
  • Joined: 03 Oct 2005
The thing is, U3Helper is intended to do application-configuration setup and backup to help running those applications from an U3-stick. Finding out which values and files to backup is NOT the purpose of my U3Helper and never will be.

This is not and never was intended for end-users. It's for U3-packagers and geeks who know how to use Filemon/Regmon and know something about the registry and typical file locations. I doubt that an end-user would know the difference between needed registry-keys and not-needed ones for some application. So this all is useless. Those who know the difference also have their tools to find out ... maybe your RegShot is amongst them.

Also when I would add this registry-compare-thingy, I'd also have to add a filesystem-compare-thingy .... and at least at that point you'd end up with so many changed files (by the system) that a normal end-user would give up at that point.

Cheers,
-mARKUS

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Thx for the script.

I created similar thing but in batch script for my installation rotines the way U3 was there, though I was not interested in hidding traces, but making application work portable.


I think that your script can not handle all situations. For instance, some apps copy things in profile, and Common Data and your script can handle only %U3_HOST_EXEC_PATH%.

Didn't check your script but is the PATH env var handled correctly if dir already exists there and are those paths later removed?
Posted Image

mbirth
  • Members
  • 40 posts
  • Last active: Jul 31 2008 11:12 AM
  • Joined: 03 Oct 2005

I think that your script can not handle all situations. For instance, some apps copy things in profile, and Common Data and your script can handle only %U3_HOST_EXEC_PATH%.

Didn't check your script but is the PATH env var handled correctly if dir already exists there and are those paths later removed?


There's the possibility to launch your app using this command:

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

This way, U3Helper will replace the env vars USERPROFILE, HOMEPATH and APPDATA with paths pointing to %U3_APP_DATA_PATH% so that everything gets instantly stored to the stick instead to the host computer. It's the way, Ceedo works.

Also you can temporarily change the PATH variable - only for that specific application.

Cheers,
-mARKUS

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006

Also you can temporarily change the PATH variable - only for that specific application.

That is not the soluton.

What if I put bunch of console utilities on the stick and I want them to be available anywhere in the system.... like i do...
Posted Image