-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathGetJScriptObject.ahk
32 lines (27 loc) · 990 Bytes
/
GetJScriptObject.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
JS := GetJScripObject()
code := "function s(a,b){return a+b}; var a1 = 1, a2 = 2; s(a1, a2)"
MsgBox, % JS.(code)
JS := CreateScriptObj()
MsgBox, % JS.(code)
*/
GetJScripObject() { ; Here we create temp file to get a custom COM server using Windows Script Components (WSC) technology.
VarSetCapacity(tmpFile, ((MAX_PATH := 260) - 14) << !!A_IsUnicode, 0)
DllCall("GetTempFileName", Str, A_Temp, Str, "AHK", UInt, 0, Str, tmpFile)
FileAppend,
(
<component>
<public><method name='eval'/></public>
<script language='JScript'></script>
</component>
), % tmpFile
JS := ObjBindMethod( ComObjGet("script:" . tmpFile), "eval" ) ; ComObjGet("script:" . tmpFile) is the way to invoke com-object without registration in the system
FileDelete, % tmpFile
Return JS
}
CreateScriptObj() {
static doc := ComObjCreate("htmlfile")
doc.write("<meta http-equiv='X-UA-Compatible' content='IE=9'>")
return ObjBindMethod(doc.parentWindow, "eval")
}