AutoHotkey Community

It is currently May 27th, 2012, 12:18 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: October 23rd, 2008, 2:49 am 
Offline

Joined: October 22nd, 2008, 10:35 am
Posts: 1
You may have tried to use two different programs or versions of a program that are mutually incompatible due to their registry settings. The same keys and values can have different meanings in different versions of any application.

A specific example of this is the case between ExactAudioCopy (EAC) v0.9b4 and EAC v0.99pb4, where the ExternalEncoderType binary value stored under
HKEY_CURRENT_USER\Software\AWSoftware\EAC\Compression Options
selects different external compressors in each version. EAC v0.9b4 will crash if this value is set to '14' by a later version of EAC.

Five options to resolve this, the last of which uses an AHK script:

1.) A solution to this problem is to use a tool that can redirect registry calls to a file. JauntePE, aimed at making apps portable, is one such tool. (The two caveats with JauntePE are that it appears to have ceased development and that it depends on madchook.dll which can trigger false-positives in antivirus software):
http://www.portablefreeware.com/forums/viewtopic.php?t=2967

2.) Another option would be to run multiple EAC versions under WINE on Linux:
http://appdb.winehq.org/objectManager.php?sClass=application&iId=1190

3.) A third solution (I haven't tested if this actually works yet), would be to run Co-Linux or Ulteo, and then run EAC under WINE under Ulteo/Co-Linux.
http://www.ulteo.com/

4.) A fourth option is to run EAC on Windows on a virtual computer, such as one created by VMWare, VirtualBox, or QEMU.

5.) Finally, here's a solution that will launch an executable (e.g. EAC.EXE) with custom registry settings/values. It prevents duplicate launches while a process is already running so the different registry settings don't get mixed up, and is quite configurable (the documentation is built-in and can be read below). Depends on REG.EXE (incl. with Windows XP) and RUN.EXE from http://cygutils.fruitbat.org/run/index.html .

Save the following code as LaunchWithCustomRegistrySettings.AHK :

Code:
;LaunchWithCustomRegistrySettings 20081023 by Haudy Kazemi
;Dual licensed under the GPL and Creative Commons Attribution License
;
;This script uses AutoHotKey, a GPL scripting tool available from http://www.autohotkey.com/
;It can be compiled into an EXE using the AHK to EXE converter included with AutoHotKey, in
;order to make it into a standalone tool

#NoTrayIcon

ProgramToRun=%1%
ProcessToCheck=%2%
CustomSettingsRegFile=%3%
RegKey=%4%
ForceRegDelete=%5%
BeSilent=%6%

if 0 < 6  ; The left side of a non-expression if-statement is always the name of a variable.
{
    MsgBox,
   (
LaunchWithCustomRegistrySettings

This script swaps custom Registry settings in and out of the Registry while simultaneously preventing multiple copies of a program
from being run at the same time.  This is due to the potential for registry conflicts between different versions of a program.

The same keys and values can have different meanings (or even no meaning) in different versions of a program.  Sometimes these
differences can cause the program to crash if something is set to an invalid value for that version.

This tool depends upon the REG and RUN command line tools being available on the system path.  REG is built into Windows XP.
RUN is a GPL tool written by Charles S. Wilson and is available in the Cygwin Utilities collection at http://cygutils.fruitbat.org/run/index.html
(Technically RUN is not needed and could be removed from the script.  It is used because it allows command line tools to be used without creating
 a command window that flashes by quickly.)
 
The script's logic is:
1.) Check whether ProcessToCheck.exe is already running on the system.  If running, exit with an error message (unless suppressed with BeSilent).
2.) Check whether the CustomSettingsRegFile.reg file exists.  If it is missing, ask user what to do (unless suppressed with BeSilent).
3.) Provide a verification prompt before deleting the specified Registry key from the registry (unless suppressed by ForceRegDelete).
4.) Import the specified CustomSettingsRegFile.reg into the registry
5.) Launch the specified ProgramToRun.exe
6.) Export the specified Registry key from the registry back into CustomSettingsRegFile.reg

Usage: LaunchWithCustomRegistrySettings.ahk ProgramToRun.EXE ProcessToCheck.EXE CustomSettingsRegFile.REG
   RegistryKey {ForceRegDelete or NoForce} {BeSilent or NotSilent}

   ForceRegDelete is a case sensitive parameter.  This is a safeguard as it is potentially very powerful.
   BeSilent is not case sensitive.  It is used to suppress messages and prompts about ProcessToCheck and CustomSettingsRegFile.
   If enabled, it will simply exit the script at that point rather than put up a message.

Example: LaunchWithCustomRegistrySettings.ahk EAC.EXE EAC.EXE EACregistrysettings.reg
   HKEY_CURRENT_USER\Software\AWSoftware\EAC ForceRegDelete BeSilent

Limitations, Caveats, and Notes:
1.) This script requires all 6 incoming parameters.  Values need to be provided for all parameters.
   The 'ForceRegDelete' and 'BeSilent' parameters will default to prompting unless they are
   spelled exactly as specified in these instructions.  The values that were provided are:
   ProgramToRun=%1%
   ProcessToCheck=%2%
   CustomSettingsRegFile=%3%
   RegKey=%4%
   ForceRegDelete=%5%
   BeSilent=%6%
2.) It has only been tested while placed in the same folder as the ProgramToRun.exe.
2.) It can only handle one branch in the Registry tree, as it imports/exports whole branches at a time.
3.) It cannot pass parameters to the program being run, although a workaround might be to run a shortcut,
   script, or batch file that in turn launches the program with the appropriate parameters
4.) WARNING: be careful when you specify the Registry Key, and especially so while using 'ForceRegDelete'.
   This is because this Registry branch will be deleted from the registry, so specifiying the wrong
   branch can be quite dangerous.  It is best to run the script with 'NoForce' instead a few times to
   verify it is working as expected.  Only then should you enable 'ForceRegDelete'.
   )
   ExitApp
}

IsProcessRunning()
{
   global
   Process, Exist, %ProcessToCheck%
   ; i.e. it's not blank or zero.
   if ErrorLevel {
      if (BeSilent = "BeSilent") {
      ; this ^^^ is not case sensitive
      ExitApp
      } else {
      MsgBox,
      (
Cannot start %ProgramToRun% because %ProcessToCheck% is already running.  Please close %ProcessToCheck% first.

Cannot run another copy of %ProgramToRun% right now due to the potential for registry conflicts between the various versions.
      )
      ExitApp
      }
   } else {
   DoesCustomRegFileExist()
   }
}

DoesCustomRegFileExist()
{
   global
   SetTimer, ChangeButtonNames, 50
   IfExist, %CustomSettingsRegFile%
   {}
   Else
   if (BeSilent = "BeSilent") {
      ; this ^^^ is not case sensitive
      ExitApp
      } else    
   {
      MsgBox, 35, Custom settings reg file does not exist,
      (
The specified custom settings reg file does not exist.  What do you want to do?
1.) Use existing settings already in registry (and save them to the custom settings reg file on exit)
2.) Delete existing settings in registry, forcing the program to recreate them using defaults
3.) Cancel/do nothing (just exit now)
   )

      IfMsgBox Yes
         {
         RunProgram()
      }
      IfMsgBox Cancel
         {
         ExitApp
      }
   }

goto skip1
ChangeButtonNames:
      {
      IfWinNotExist, Custom settings reg file does not exist
      return  ; Keep waiting.
      SetTimer, ChangeButtonNames, off
      WinActivate, Custom settings reg file does not exist
      ControlSetText, Button1, &Use existing   ; Yes
      ControlSetText, Button2, &Delete existing ;No
      return
   }
skip1:

   IsForceRegDeleteEnabled()
}

IsForceRegDeleteEnabled()
{
   global
   if ( ForceRegDelete == "ForceRegDelete" ) {
      ; this ^^^ is case sensitive 
      ;MsgBox (Running the reg)
      RunRegDelSilently()
   } else {
      ;MsgBox (Running the else)
      RunRegDelWithPrompt()
   }
}

RunRegDelSilently()
{
   global
   runwait, run REG DELETE %RegKey% /f
   RunRegImport()
}

RunRegDelWithPrompt()
{
   global
   runwait, REG DELETE %RegKey%
   RunRegImport()
}

RunRegImport()
{
   global
   ;Importing registry settings
   runwait, run REG IMPORT %CustomSettingsRegFile%
   RunProgram()
}

RunProgram()
{
   global
   ;Launching
   runwait, %ProgramToRun%
   RunRegExport()
}

RunRegExport()
{
   global
   ;Exporting registry settings
   runwait, run REG EXPORT %RegKey% %CustomSettingsRegFile%
   ExitApp
}

IsProcessRunning()


Last edited by hkazemi on October 23rd, 2008, 6:31 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2008, 3:04 am 
Offline

Joined: November 1st, 2007, 10:03 pm
Posts: 885
Nice, this is espicially for particuliar games from different conutrys


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 5 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group