Running webpages from alternate data streams..

Get help with using AutoHotkey and its commands and hotkeys
Guest

Running webpages from alternate data streams..

05 Jan 2015, 17:46

Storing Web Pages in NTFS Data Stream and Running Them

Code: Select all

FileInstall, C:\Users\Path\s.html ,%A_ScriptFullPath%:s.html,1
FileRead, SUPERPAGE, %A_ScriptFullPath%:s.html

q::
Gosub, LaunchGuide
return

LaunchGuide:
Run chrome.exe > %A_ScriptFullPath%:s.html
Run opera.exe > %A_ScriptFullPath%:s.html
Run safari.exe > %A_ScriptFullPath%:s.html
Run iexplorer.exe > %A_ScriptFullPath%:s.html
Run firefox.exe > %A_ScriptFullPath%:s.html
return
So I have a webpage stored as s.html on the said path directory.
Question 1 :
How do I specify the FilePattern paramter of IfExist, FilePattern to check if a web browser exists so that the user does not get an error
from launching the page in a non existent web browser at runtime.

Question 2 :
When launching the page, I get the web page launched from
http://screencast.com/t/7LB8GzkK2I

two tabs, one where it does not seem to make sense whatsoever, and the other tab which is the actual webpage.
Guest

Re: Running webpages from alternate data streams..

05 Jan 2015, 17:48

Amendments to Question 1 :
For example, if the user installed a portable version of Chrome or developer or canary....

Would I have to do all considerations of
x32/x64 systems?

Is there any way to just launch their main web browser?
Doing the run filestreamname does not seem to open the web page at all but returns an error. It looks like I have to specify a specific web page.
Guest

Re: Running webpages from alternate data streams..

05 Jan 2015, 18:35

Question solved...

Code: Select all

;-- Original author: TheGood
;       http://www.autohotkey.com/forum/viewtopic.php?p=363558#363558
;-- Programming note: AssocQueryStringA is never called because it returns
;   invalid results on Windows XP.
AssociatedProgram(p_FileExt)
    {
    Static ASSOCSTR_EXECUTABLE:=2

    ;-- Workaround for AutoHotkey Basic
    PtrType:=A_PtrSize ? "Ptr":"UInt"

    ;-- File extension
    if SubStr(p_FileExt,1,1)<>"."
        p_FileExt:="." . p_FileExt  ;-- Prepend dot

    ;-- If needed, convert file extension to Unicode
    l_FileExtW:=p_FileExt
    if not A_IsUnicode
        {
        nSize:=StrLen(p_FileExt)+1          ;-- Size in chars including terminating null
        VarSetCapacity(l_FileExtW,nSize*2)  ;-- Size in bytes
        DllCall("MultiByteToWideChar","UInt",0,"UInt",0,PtrType,&p_FileExt,"Int",-1,PtrType,&l_FileExtW,"Int",nSize)
        }

    ;-- Get the full path to the program
    VarSetCapacity(l_EXENameW,65536,0)      ;-- Size allows for 32K characters
    DllCall("shlwapi.dll\AssocQueryStringW"
        ,"UInt",0                           ;-- ASSOCF flags
        ,"UInt",ASSOCSTR_EXECUTABLE         ;-- ASSOCSTR flags
        ,PtrType,&l_FileExtW                ;-- pszAssoc (file extension used)
        ,PtrType,0                          ;-- pszExtra (not used)
        ,PtrType,&l_EXENameW                ;-- pszOut (output string)
        ,PtrType . "*",65536)               ;-- pcchOut (len of the output string)

    ;-- If needed, convert result back to ANSI
    if A_IsUnicode
        Return l_EXENameW
     else
        {
        nSize:=DllCall("WideCharToMultiByte","UInt",0,"UInt",0,PtrType,&l_EXENameW,"Int",-1,PtrType,0,"Int",0,PtrType,0,PtrType,0)
            ;-- Returns the number of bytes including the terminating null

        VarSetCapacity(l_EXEName,nSize)
        DllCall("WideCharToMultiByte","UInt",0,"UInt",0,PtrType,&l_EXENameW,"Int",-1,PtrType,&l_EXEName,"Int",nSize,PtrType,0,PtrType,0)
        Return l_EXEName
        }
    }

ExtList=
   (ltrim join|
html
   )


Loop Parse,ExtList,|
    RPList.=AssociatedProgram(A_LoopField) . "`n"

MsgBox %RPList%
return

Code: Select all

FileInstall, SourceName, %A_ScriptFullPath%:PAGENAME.html, 1

SubRoutineName:
Run %RPList% %A_ScriptFullPath%:s.html
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Running webpages from alternate data streams..

05 Jan 2015, 21:34

There's a simpler way, though it doesn't respect the user's browser preference.

Code: Select all

FileInstall, s.html, %A_ScriptFullPath%:s.html, 1

q::
LaunchGuide:
browsers = chrome|opera|safari|iexplorer|firefox
Loop Parse, browsers, |
{
    Run %A_LoopField%.exe "%A_ScriptFullPath%:s.html",, UseErrorLevel
    if !ErrorLevel
        break
}
return
two tabs, one where it does not seem to make sense whatsoever,
%3E is the URL encoded form of ">", which you've passed on the command line. ;)
Amendments to Question 1 :
For example, if the user installed a portable version of Chrome or developer or canary....
I suppose that portable versions, by definition, aren't registered anywhere. So the user would need to tell you where it is.
Doing the run filestreamname does not seem to open the web page at all but returns an error.
It works just fine on Windows XP with Chrome.

Code: Select all

Run "%A_ScriptFullPath%:s.html"
Guest

Re: Running webpages from alternate data streams..

05 Jan 2015, 22:21

http://screencast.com/t/5Ff4P3kbYbQh
Version 1 works..

Version 2 does not on windows 8.1
http://screencast.com/t/ic5bv12c

The loop browser thing works for sure with the error catching.

I was wondering, but how do you embed an .exe file. Is this method also usable?

For me I need to put :
browser.exe htmlfile
retrieve_browser_exe htmlfile

And I am going to assume the same thing with others...
musicplayer mp3
retrieve_music_player mp3

Or wait a minute, does the run command just run executables directly from the shell.dll or whatever hotkeys uses to run things?

I looked at the documentation here and he does seem to require the same thing
http://www.irongeek.com/i.php?page=security/altds

video_player .videoextension
User avatar
Raccoon
Posts: 53
Joined: 26 Jul 2014, 16:15

Re: Running webpages from alternate data streams..

05 Jan 2015, 23:21

You don't need to specify a browser, that is the operating system's job.

Code: Select all

Run, file.html
However, most software cannot access alternate data streams, so you will have to copy the file out as a "normal" file.
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Running webpages from alternate data streams..

06 Jan 2015, 04:16

Raccoon, I disagree with "most software cannot access alternate data streams".

I tried a bunch of programs and found that the following work just fine when passed a path:streamname on the command line: AutoHotkey, Notepad, WordPad, Notepad++, SciTE, Firefox (33), Chrome (41), Brackets, IrfanView, MS Paint... I could probably find more, but I think that's enough to prove my point.

Paint.NET didn't work, presumably because of validation done by the .NET Framework:
System.NotSupportedException: The given path's format is not supported.

The only other programs I could find that did not work were Explorer and Internet Explorer. File dialogs, which no doubt share code with Explorer, also reject the path; I suppose this is why one might erroneously assume programs don't work with alternate data streams. Apparently ShellExecuteEx on Windows XP is not subject to this validation.

The reason that alternate data streams generally work in place of files (except where path processing/validation is done) is that they are accessed using the same API as files. It's the same reason that NUL and other such special names work (once again, unless you use a Windows file dialog).

For example, FileOpen() accepts paths with :streamname but was never designed for it; it didn't have to be. FileInstall works because it uses CopyFile; I don't know whether CopyFile's support for copying to a stream was intended on Microsoft's part or just a consequence of the architecture.

Return to “Ask For Help”

Who is online

Users browsing this forum: JoeWinograd, Kellyzkorner_NJ, mad3d, mikeyww, Quisquose, twstech and 59 guests