AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Portable Autohotkey

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
shajul



Joined: 15 Sep 2006
Posts: 33
Location: India

PostPosted: Thu May 22, 2008 7:44 pm    Post subject: Portable Autohotkey Reply with quote

I have AHK program folder on my pen drive, used on computers other than mine. But all the settings of ahk, the shell integration was very much missed!

Hence i have written a script to register .ahk filetype temporarily with the current drive:folder of AHK, and un-register it after use!

This way i can carry the same AHK program folder that i have on my home machine.

Just copy "register.bat" to the AHK program directory in the USB stick (e.g. g:\portableapps\autohotkey and "Register_AHK.ahk" into the "Extras" folder. (e.g. g:\portableapps\autohotkey\extras)

Code for register.bat:
Code:
@echo off
start Autohotkey.exe Extras\Register_AHK.ahk
@exit


Code for Register_AHK.ahk:

Code:
/*  Register AHK in portable mode - by Shajul
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Used to register AHK in portable mode
*/

;;********** Settings, Variable Declarations **********
#SingleInstance Force
#NoEnv
#Persistent
OnExit, quit

programName = Register AHK
programVersion = 0.01
programFullName = %programName% v%programVersion%
programAuthor = Shajul


;;********** Auto-Execute Section **********
GoSub, trayMenu    ; construct tray menu : OPTIONAL
SetWorkingDir %A_ScriptDir%\..
;;********** User Configuration **********
Compiler=%A_WorkingDir%\Compiler\Compile_AHK.exe
param = %1%.
if param = -u.
    Goto, unreg

reg:
RegWrite, REG_SZ, HKCR, .ahk,,AutoHotkeyScript
RegWrite, REG_SZ, HKCR, .ahk\ShellNew,FileName,Template.ahk

RegWrite, REG_SZ, HKLM, SOFTWARE\Classes\.ahk,,AutoHotkeyScript
RegWrite, REG_SZ, HKLM, SOFTWARE\Classes\.ahk\ShellNew,Filename,Template.ahk

RegWrite, REG_SZ, HKCR, AutoHotkeyScript,,AutoHotkey Script
RegWrite, REG_SZ, HKCR, AutoHotkeyScript\DefaultIcon,,%A_WorkingDir%\AutoHotkey.exe`,1
RegWrite, REG_SZ, HKCR, AutoHotkeyScript\Shell,,Open
RegWrite, REG_SZ, HKCR, AutoHotkeyScript\Shell\Compile_AHK,,Compile with Options
RegWrite, REG_SZ, HKCR, AutoHotkeyScript\Shell\Compile_AHK\Command,,"%A_WorkingDir%\Compiler\Compile_AHK.exe" "`%l"
RegWrite, REG_SZ, HKCR, AutoHotkeyScript\Shell\Open,,Run Script
RegWrite, REG_SZ, HKCR, AutoHotkeyScript\Shell\Open\Command,,"%A_WorkingDir%\AutoHotkey.exe" "`%1" `%*

RegWrite, REG_SZ, HKLM, SOFTWARE\Classes\AutoHotkeyScript,,AutoHotkey Script
RegWrite, REG_SZ, HKLM, SOFTWARE\Classes\AutoHotkeyScript\DefaultIcon,,%A_WorkingDir%\AutoHotkey.exe`,1
RegWrite, REG_SZ, HKLM, SOFTWARE\Classes\AutoHotkeyScript\Shell,,Open
RegWrite, REG_SZ, HKLM, SOFTWARE\Classes\AutoHotkeyScript\Shell\Compile_AHK,,Compile with Options
RegWrite, REG_SZ, HKLM, SOFTWARE\Classes\AutoHotkeyScript\Shell\Compile_AHK\Command,,"%Compiler%" "`%l"
RegWrite, REG_SZ, HKLM, SOFTWARE\Classes\AutoHotkeyScript\Shell\Open,,Run Script
RegWrite, REG_SZ, HKLM, SOFTWARE\Classes\AutoHotkeyScript\Shell\Open\Command,,"%A_WorkingDir%\AutoHotkey.exe" "`%1" `%*
Return

;;********** Subroutines **********
trayMenu:
   Menu, Tray, NoStandard
   IfExist, %A_WorkingDir%\Compiler\Compile_AHK.exe
     Menu, Tray, Icon, %Compiler%
   Menu, Tray, Tip, %programFullName%
   Menu, Tray, Add, &Unregister AHK, unreg
   Menu, tray, Default, &Unregister AHK
   Menu, Tray, Add, &About, about
   Menu, Tray, Add
   Menu, Tray, Add, &Quit, quit
Return

unreg:
RegDelete, HKCR, .ahk
RegDelete, HKLM, SOFTWARE\Classes\.ahk
RegDelete, HKCR, AutoHotkeyScript
RegDelete, HKLM, SOFTWARE\Classes\AutoHotkeyScript
ExitApp
return

about:
   MsgBox, 64, %programFullName%,
   ( LTrim
      %programFullName%
      %A_Space%by %programAuthor%

      Used to register AHK in portable mode
   )
Return

quit:
ExitApp
Return


I am not sure this has been posted before (search returned nothing similar).. Also it has been tested only on WinXP2

Hope u find it useful!
Back to top
View user's profile Send private message Yahoo Messenger
BoBo²
Guest





PostPosted: Fri May 23, 2008 8:58 am    Post subject: Reply with quote

AFAIK you could use an AutoRun file instead of a batch, which will be executed once you connect the USB stick (removable drive) to the system ... ?
Back to top
shajul



Joined: 15 Sep 2006
Posts: 33
Location: India

PostPosted: Fri May 23, 2008 3:06 pm    Post subject: Thanks Reply with quote

@ Bobo2: Thanks for the idea!!
I can make make a shell context menu item..

Code:

[autorun]
open=autorun.exe   ;default autorun exe
icon=foobar.ico
shell\ahk=&Register AHK
shell\ahk\command=portableapps\autohotkey\autohotkey.exe portableapps\autohotkey\Extras\Register_AHK.ahk
label=MyUSBStick
Back to top
View user's profile Send private message Yahoo Messenger
infogulch



Joined: 27 Mar 2008
Posts: 184

PostPosted: Fri May 23, 2008 3:53 pm    Post subject: Reply with quote

Cool! Is that autorun working? (I wouldn't know. Smile ) So, I'd just name it Autorun.inf an put it in the root dir of the drive? Thnx. Smile

Since you're making it mostly automatic, how about making it totally transparent? Like:
Code:
#NoTrayIcon
SetTimer, CheckDrive, 1000

CheckDrive:
   IfNotExist, %A_ScriptFullPath%
      Gosub, unreg
return

quit:    ;when this script exits, it automatically unregisters ahk
unreg:
   RegDelete, ....
   ...
ExitApp

I don't know, if you unplug your drive while stuff is running, does it keep going? If not, the CheckDrive timer doesn't do much. And if you wanted to still get to your icon, you could do something like this:
Code:
~+Ctrl::
~^Shift::
   Menu, Tray, Icon
return

~+Ctrl Up::
~^Shift Up::
   Menu, Tray, NoIcon
return
That's just my 2 cents anyway. Thanks agian! this will be really handy! Can't wait to use it. Very Happy
_________________
A great Beginner's Tutorial
Back to top
View user's profile Send private message
shajul



Joined: 15 Sep 2006
Posts: 33
Location: India

PostPosted: Fri May 23, 2008 4:05 pm    Post subject: thanks again Reply with quote

@ infogulch:
Your idea is really great!!..
but if you try "Safely remove hardware", it wont dismount the drive unless all programs launched from the drive are exitted!!
But if you are the type of guy who just pulls it out without worrying Wink then ur code works great!!

thanks for the idea!! maybe still better is if you write your own eject program for the drive, eg. Devject
Back to top
View user's profile Send private message Yahoo Messenger
JoeSchmoe



Joined: 17 Feb 2008
Posts: 57

PostPosted: Sun Jul 13, 2008 4:08 am    Post subject: Reply with quote

I have a quick question about the above code (in the original post)... I would have thought that it would be redundant to modify both HKCR and HKLM\SOFTWARE\Classes, doing the same thing to both. My undertanding is that HKCR is basically an alias for the software\classes sections of both HKCU and HKLM, with a fairly simple algorithm to combine the data in both. Thus, it isn't clear to me why one would need to enter it twice, as the above code does.

Can anyone help with this?
Back to top
View user's profile Send private message
shajul



Joined: 15 Sep 2006
Posts: 33
Location: India

PostPosted: Sun Jul 13, 2008 4:43 pm    Post subject: you are right! Reply with quote

you are right, only one is required..
it was just that i searched for the key and changed all i found!
Back to top
View user's profile Send private message Yahoo Messenger
JoeSchmoe as guest
Guest





PostPosted: Sun Jul 13, 2008 5:08 pm    Post subject: Reply with quote

Thanks!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group