AHK Portable/Dateizuordnung Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

AHK Portable/Dateizuordnung

Post by BoBo » 18 May 2022, 00:31

Moin Loyds :)
Mit "portablen" Anwendungen werden in der Regel Programme beschrieben, welche zwar keine Installation erfordern, jedoch alle (?) Funktionen einer installierten Version beinhalten. Bei AHK wird hingegen die ZIP-Version bereits als portable verstanden, dabei fehlt mir jedoch eine Funktion der "Vollversion" - die Zuordnung der Dateiendung (*.ahk) zum Interpreter (AutoHotkey.exe), welche ja systembedingt in der Registry gesetzt wird. Correct me if I'm wrong! Wenn jedoch durch Company-policy der Zugang zur selbigen unterbunden wird ("missing [local] admin rights"), obwohl AHK erlaubt ist, wird es tricky :think: wie :arrow: hier angesprochen.

Dies betrifft für mich ad-hoc die file type association, die ohne Registry-Eintrag IMHO nicht gehen würde, oder?

Hat jemand von Euch evtl. schon mal eine app portable generiert, so wie hier beschrieben?
https://portableapps.com/manuals/PortableApps.comLauncher/intro/overview.html
https://portableapps.com/manuals/PortableApps.comLauncher/topics/registry.html#registry

Frage zu einer artverwandten Problemstellung: der Versuch eine INI-Datei wie folgt zu starten Run % "<vollständiger Pfad zur INI>" wird unter AHK mit Fehler retourniert, ein Doppelklick im Explorer startet diese Datei jedoch problemlos im Editor/notepad? Warum scheitert AHK - denn eine Zuordnung scheint demnach ja bereits gegeben? :think:

gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

Re: AHK Portable/Dateizuordnung

Post by gregster » 18 May 2022, 01:23

BoBo wrote:
18 May 2022, 00:31
Frage zu einer artverwandten Problemstellung: der Versuch eine INI-Datei wie folgt zu starten Run % "<vollständiger Pfad zur INI>" wird unter AHK mit Fehler retourniert, ein Doppelklick im Explorer startet diese Datei jedoch problemlos im Editor/notepad? Warum scheitert AHK - denn eine Zuordnung scheint demnach ja bereits gegeben? :think:
Bei mir öffnet sich die ini-Datei mit run in Notepad, aber das liegt an den Einstellungen zur Standardaktion für einen bestimmten Dateityp, denk ich.
Was sagt denn der Fehler?

Es gibt ja verschiedene System-Verben, wie edit, print oder open (AHK-Skripte kannst du ja u. a. starten oder editieren), die man mit run verwenden kann. Also probier mal explizit das Editieren:

Code: Select all

Run, edit "C:\My File.ini"
https://www.autohotkey.com/docs/commands/Run.htm#Remarks

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: AHK Portable/Dateizuordnung

Post by just me » 18 May 2022, 02:18

Moin @BoBo,

die Dateiverknüpfungen können auch komplett im HKCU-Zweig der Registrierung angelegt werden. Dafür braucht man normalerweise keine Adminrechte. Es lässt sich auch mit einem AHK-Skript bewerkstelligen.

(Mir ist allerdings nicht klar, warum jemand die Benutzung von AHK erlauben, die Installation aber verweigern sollte.)

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: AHK Portable/Dateizuordnung  Topic is solved

Post by BoBo » 18 May 2022, 02:20

@gregster - Moin. System-Verben alle ausprobiert, gehn leider nicht.

Die Fehlermeldung:
Error: Failed attempt to launch program or document:
Action: < edit "C:\_MyPrograms\Notepad2\Notepad2.ini">
Params: <>

Specifically: Das System kann die angegebene Datei nicht finden.


Weitergesucht ... Fehler gefunden! Ließ sich wie folgt provozieren:

Code: Select all

; Run % !(assocIndex[ext]="") ? assocIndex[ext] . " """ . file[A_Index] . """"  : " """ . file[A_Index] . """"   ; <leerzeichen>"<dateipfad>"  (scheitert)
  Run % !(assocIndex[ext]="") ? assocIndex[ext] . " """ . file[A_Index] . """"  :  """" . file[A_Index] . """"   ; "<dateipfad>"               (funktioniert)
  Run % !(assocIndex[ext]="") ? assocIndex[ext] . " """ . file[A_Index] . """"  :         file[A_Index]          ;  <dateipfad>                (funktioniert)
Fazit: ein (unnötig) führendes Leerzeichen ergibt einen Missmatch für die Dateinamen-Suche/Pfad-Auflösung. Bug oder feature? :think:

Code: Select all

F8:: Run % "my.ini"                          ; success
F9:: Run % " my.ini"                         ; fail
F10::Run % "notepad.exe" " my.ini"           ; success
F11::Run % "notepad.exe" A_Space "my.ini"    ; success
Danke für deinen Support :thumbup:

@just me - Gute Frage. In der Regel isses Bequemlichkeit. Mehr Ausnahmen, mehr administrativer Aufwand. Ich habe AHK final sogar als inHouse Downloadoption durchbekommen. Wobei es dann allerdings über Jahre dieselbe Version blieb. Habs deshalb auch nicht gehyped da mehr user gerne auch mehr Probleme ergeben, und damit die Gefahr bestand das da einer kalte Füße bekommt und es ausgelistet wird. Der Motive gibt es viele :)

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: AHK Portable/Dateizuordnung

Post by BoBo » 18 May 2022, 02:44

Die von @just me angesprochene "User Choice" FTA (file type association) im HCKU-Zweig der registry - hat dazu schon mal einer etwas (mit AHK) gebastelt? :shifty:

Nach 'Aktenlage' sieht das nämlich irgendwie noob-unfriendly aus... schon allein die Länge der links :shifty:

https://answers.microsoft.com/en-us/windows/forum/all/windows-file-association-explained-for-desktop/cfa62c00-82e0-4d05-b302-3444ab930bb7
https://james-rankin.com/articles/per-user-ftas-file-type-associations-in-windows-10-server-2012-r2-and-server-2016-the-final-word/

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: AHK Portable/Dateizuordnung

Post by just me » 18 May 2022, 03:48

Hi @BoBo,

ich meinte nicht die 'User Choice'. Nachdem ich die von Dir verlinkten Dokumente gelsen habe, bin ich aber nicht mehr sicher, ob 'meine Methode' unter Win 10/11 noch funktioniert. Die besteht darin, die Einträge .ahk und AutoHotkeyScript aus dem HKCR-Zweig einer Registrierung mit installiertem AHK auszulesen und in den Zweig HKEY_CURRENT_USER\SOFTWARE\Classes zu schreiben. Das hat mal funktioniert.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: AHK Portable/Dateizuordnung

Post by BoBo » 18 May 2022, 04:12

@just me - das Problem ist doch, das es beim oben geschilderten/verlinkten Fall aufgrund Restriktion keine vorherige AHK-"Installation" gibt, insofern wäre der Transfer von HKCR nach HKCU schwerlich möglich? Allerdings sind/sollten uns die default AHK Einträge in HKCR doch bekannt sein, wenn also HKCU wirklich zugänglich wäre...:think:

fredchf
Posts: 54
Joined: 30 Sep 2013, 14:55

Re: AHK Portable/Dateizuordnung

Post by fredchf » 18 May 2022, 17:58

Hallo!
Ich hatte mir zu Windows XP Zeiten zwei Scripte zum Sichern und Wiederherstellen von Dateierweiterungen gebastelt. Damit könntest du direkt mehrere Erweiterungen und Anwendungen zuordnen. Bei aktuellem Windows sind aber vielleicht Adminrechte nötig (nicht getestet).
https://docs.microsoft.com/de-de/windows-server/administration/windows-commands/ftype

Sichern

Code: Select all

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <[email protected]>
;
; Script Function:
;	Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
RunWait, %ComSpec% /c assoc >assoc%A_Now%.txt
RunWait, %ComSpec% /c ftype >ftype%A_Now%.txt
Wiederherstellen

Code: Select all

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <[email protected]>
;
; Script Function:
;	Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

backup_ext_txt = assoc.txt
backup_types_txt = ftype.txt

RunWait, %ComSpec% /c FOR /F "tokens=* delims=" `%G IN (%backup_types_txt%) DO FTYPE `%G
RunWait, %ComSpec% /c FOR /F "tokens=* delims=" `%G IN (%backup_ext_txt%) DO ASSOC `%G
Auszug assoc

Code: Select all

.323=h323file
.386=vxdfile
.3g2=KLCP.3GP
.3gp=KLCP.3GP
.3gp2=KLCP.3GP
.3gpp=KLCP.3GP
.7z=WinRAR
.8ba=Photoshop.PlugIn
.8bc=Photoshop.PlugIn
.8be=Photoshop.PlugIn
.8bf=Photoshop.PlugIn
.8bi=Photoshop.PlugIn
.8bp=Photoshop.PlugIn
.8bs=Photoshop.PlugIn
.8bx=Photoshop.PlugIn
.8by=Photoshop.PlugIn
.8li=Photoshop.PlugIn
.aac=
.abr=Photoshop.BrushesFile
.aca=Agent.Character.2
.acb=Photoshop.ColorBooks
.ace=WinRAR
.acf=Photoshop.CustomFilterKernel
.acl=ACLFile
.aco=Photoshop.SwatchesFile
.acp=
.acs=Agent.Character2.2
.act=Photoshop.ColorTableFile
.acv=Photoshop.CurvesFile
.acw=acwfile
.ade=Access.ADEFile.11
.adn=Access.BlankProjectTemplate.11
.ado=Photoshop.DuotoneSettingsFile
.adp=Access.Project.11
.ahk=AutoHotkeyScript
.ahs=Photoshop.HalftoneScreens
.ahu=Photoshop.HueSatFile
Auszug ftype

Code: Select all

Access.ADEFile.11="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP "%1"
Access.Application.11="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP "%1"
Access.BlankDatabaseTemplate.11="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP /NEWDB "%1"
Access.BlankProjectTemplate.11="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP /NEWDB "%1"
Access.DatabaseWizardTemplate.11="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP /DBWIZ "%1"
Access.Extension.11=C:\PROGRA~1\MICROS~2\OFFICE11\MSACCESS.EXE /NOSTARTUP "%1"
Access.MDEFile.11="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP "%1"
Access.Project.11="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP "%1"
Access.Shortcut.DataAccessPage.1="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP /SHELLSYSTEM [OpenDataAccessPage "%1"]
Access.Shortcut.Diagram.1="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP /SHELLSYSTEM [OpenDiagram "%1"]
Access.Shortcut.Form.1="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP /SHELLSYSTEM [OpenForm "%1"]
Access.ShortCut.Function.1="C:\PROGRA~1\MICROS~2\OFFICE11\MSACCESS.EXE" /SHELLSYSTEM [OpenFunction "%1"]
Access.Shortcut.Macro.1="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP /SHELLSYSTEM [ShellOpenMacro "%1"]
Access.Shortcut.Module.1="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP /SHELLSYSTEM [OpenModule "%1"]
Access.Shortcut.Query.1=C:\PROGRA~1\MICROS~2\OFFICE11\MSACCESS.EXE /NOSTARTUP /SHELLSYSTEM [OpenQuery "%1"]
Access.Shortcut.Report.1="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP /SHELLSYSTEM [OpenReport "%1",2]
Access.Shortcut.StoredProcedure.1="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP /SHELLSYSTEM [OpenStoredProcedure "%1"]
Access.Shortcut.Table.1=C:\PROGRA~1\MICROS~2\OFFICE11\MSACCESS.EXE /NOSTARTUP /SHELLSYSTEM [OpenTable "%1"]
Access.Shortcut.View.1="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP /SHELLSYSTEM [OpenView "%1"]
Access.WizardDataFile.11="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP "%1"
Access.Workgroup.11="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE" /NOSTARTUP "%1"
accesshtmlfile="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE"
accessthmltemplate="C:\Programme\Microsoft Office\OFFICE11\MSACCESS.EXE"
acrobat=C:\Programme\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe /u "%1"
AcroDist="C:\Programme\Adobe\Acrobat 7.0\Distillr\AcroDist.exe" "%1"
AcroDistJobOptions="C:\Programme\Adobe\Acrobat 7.0\Distillr\acrodist.exe" /E "%1"
AcroExch.Document="C:\Programme\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe" "%1"
AcroExch.Document.7="C:\Programme\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe" "%1"
AcroExch.FDFDoc="C:\Programme\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe" "%1"
AcroExch.JDFJobDef.1="C:\Programme\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe" "%1"
AcroExch.RMFFile="C:\Programme\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe" "%1"
AcroExch.XDPDoc="C:\Programme\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe" "%1"
AcroExch.XFDFDoc="C:\Programme\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe" "%1"
acwfile=%SystemRoot%\system32\accwiz.exe %1
AIFFFile="C:\Programme\Windows Media Player\wmplayer.exe"  /Open "%L"
Application.Manifest=rundll32.exe dfshim.dll,ShOpenVerbApplication %1
Application.Reference=rundll32.exe dfshim.dll,ShOpenVerbShortcut %1
ASFFile="C:\Programme\Windows Media Player\wmplayer.exe" /prefetch:7 /Open "%L"
ASXFile="C:\Programme\Windows Media Player\wmplayer.exe"  /Open "%L"
AUFile="C:\Programme\Windows Media Player\wmplayer.exe"  /Open "%L"
AutoHotkeyScript="C:\Programme\AutoHotkey\AutoHotkey.exe" "%1" %*
AVIFile="C:\Programme\Windows Media Player\wmplayer.exe" /prefetch:8 /Open "%L"
batfile="%1" %*
BPDXFileType="C:\Programme\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe" "%1"
Briefcase=explorer.exe %1

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: AHK Portable/Dateizuordnung

Post by BoBo » 19 May 2022, 02:19

Dassama cool! Merci :thumbup: Damit ließe sich evtl. "Open With..." dynamisieren :mrgreen: (wobei, müsste dazu nicht nachfolgend die Registry aktualisiert werden? :think:).

"Wenn Sie eine Dateizuordnung erstellen oder ändern, ist es wichtig, das System darüber zu informieren, dass Sie eine Änderung vorgenommen haben. Rufen Sie dazu SHChangeNotify auf und geben Sie das SHCNE_ASSOCCHANGED-Ereignis an. Wenn Sie SHChangeNotify nicht aufrufen, wird die Änderung möglicherweise erst erkannt, nachdem das System neu gestartet wurde."

Quelle:
https://docs.microsoft.com/de-de/windows/win32/shell/fa-file-types


... was doch genau das wäre was wir brauchen um ein Registry-Update vornehmen zu können, ohne NEU zu booten! :o

Vielleicht kann ich das in einem nächsten Leben hinbekommen, ansonsten bleibt mir nur:
"HILFE! Bekommt ein solches Ereignis (ein möglicherweise "Einzeiler") jemand von Euch hingeskriptet?"

Selbstbefragung: gibt es das auch für anderweitige Registry-Änderungen? Es scheint so.
Nun, wer auch immer etwas damit anfangen kann: https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-ishellchangenotify-onchange (English)

JFTR:
https://docs.microsoft.com/de-de/windows/win32/shell/fa-how-work (Deutsch)
https://docs.microsoft.com/en-us/windows/win32/shell/fa-how-work (English)
https://docs.microsoft.com/de-de/windows/win32/shell/fa-file-types (Deutsch)
https://docs.microsoft.com/en-us/windows/win32/shell/fa-file-types (English)

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: AHK Portable/Dateizuordnung

Post by just me » 20 May 2022, 04:36

Moin @BoBo,

hier mal ein ungetesteter Versuchsballon. Wenn Du das AHK-Zip entpackt hast, musst Du die gewünschte Exe-Datei nach AutoHotkey.exe und die zugehörige Bin-Datei im Compiler Verzeichnis nach AutoHotkeySC.bin kopieren.
Wenn Du dann das folgende Skript als AutoHotkey.ahk in das Verzeichnis der AutoHotkey.exe legst, sollte es bei Doppelklick auf die Exe ausgeführt werden. An den Registrierungseinträgen musst Du wahrscheinlich noch etwas schrauben:

Code: Select all

#NoEnv
#SingleInstance, Force
AhkDir  := A_ScriptDir
Editor  := "Notepad.exe"
RegRoot := "HKCU\SOFTWARE\Classes"
; .ahk -----------------------------------------------------------------------------------------------------------------
RegWrite, REG_SZ, %RegRoot%\.ahk, , AutoHotkeyScript
RegWrite, REG_SZ, %RegRoot%\.ahk\ShellNew, FileName, Template.ahk ; ????
; AutoHotkeyScript -----------------------------------------------------------------------------------------------------
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript, , AutoHotkey Script
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript\DefaultIcon, , %AhkDir%\AutoHotkey\AutoHotkey.exe`,1
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript\Shell, , Edit ; or Open !!!!! Standardaktion für Doppelklick !!!!!
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript\Shell\Compile, , Compile Script
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript\Shell\Compile\Command, , "%AhkDir%\Compiler\Ahk2Exe.exe" /in "`%l" `%*
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript\Shell\Compile-Gui, , Compile Script (GUI)...
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript\Shell\Compile-Gui\Command, , "%AhkDir%\Compiler\Ahk2Exe.exe" /gui /in "`%l" `%*
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript\Shell\Edit, , Edit Script
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript\Shell\Edit\Command, , "%Editor%" "`%1"
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript\Shell\Open, , Run Script
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript\Shell\Open\Command, , "%AhkDir%\AutoHotkey.exe" "`%1" `%* ;  /CP65001 ???
; ----------------------------------------------------------------------------------------------------------------------
; docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shchangenotify
; SHCNE_ASSOCCHANGED 0x08000000
; A file type association has changed. SHCNF_IDLIST must be specified in the uFlags parameter.
; dwItem1 and dwItem2 are not used and must be NULL. This event should also be sent for registered protocols.
; SHCNF_IDLIST       0x0000
; Return value       None
DllCall("Shell32.dll\SHChangeNotify", "Int", 0x08000000, "UInt", 0x0000, "Ptr", 0, "Ptr", 0)

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: AHK Portable/Dateizuordnung

Post by BoBo » 23 May 2022, 10:39

Merci, werde es die kommenden Tage mal ausprobieren. Sorry für das (ver)späte(te) feedback :oops:

User avatar
Gerdi
Posts: 185
Joined: 03 Aug 2015, 18:48
Location: Germany
Contact:

Re: AHK Portable/Dateizuordnung

Post by Gerdi » 25 Jun 2022, 17:09

Eventuell hilft folgendes jemandem:

Die 1:1 AHK Portable-Installation wurde mit 2 Aktionen lauffähig gemacht:
1. Doppelklick auf eine AHK-Datei ... immer mit AutoHotKey.exe öffnen.
2. Registry-Eintrag ergänzen:
[HKEY_CLASSES_ROOT\Applications\AutoHotKey.exe\shell\open\command]
@="\"C:\\...\\AutoHotKey.exe\" /CP65001 \"%1\" %*"

PS. ohne 2. konnten keine Parameter an das AHK-Skript übergeben werden.
1. und 2. konnte ich ohne Adminrechte durchführen.
Win 10 Home (x64) and Win 11 Pro N
https://github.com/Grrdi/ZackZackOrdner/archive/master.zip --> get folders on the quick

Post Reply

Return to “Ich brauche Hilfe”