anonymous1184

PipeRun.ahk

Jul 4th, 2022 (edited)
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PipeRun("MsgBox Hello World!")
  2.  
  3. code =
  4. (%
  5.     MsgBox % "1+2+3+4+5+6+7+8+9 = " Sum(1,2,3,4,5,6,7,8,9)
  6.     Sum(Args*) {
  7.         sum := 0
  8.         for k,v in Args
  9.             sum += v
  10.         return sum
  11.     }
  12. )
  13. PipeRun(code)
  14.  
  15.  
  16. return ; End of auto-execute
  17.  
  18.  
  19. PipeRun(Script) {
  20.     pipes := []
  21.     pipeName := "\\.\pipe\AHK" A_TickCount
  22.     loop 2 {
  23.         hPipe := DllCall("Kernel32\CreateNamedPipe", "Str",pipeName, "UInt",2
  24.             , "UInt",0, "UInt",255, "UInt",0, "UInt",0, "UInt",0, "Ptr",0)
  25.         if (hPipe = -1)
  26.             return false
  27.         pipes.Push(hPipe)
  28.     }
  29.     try {
  30.         fn := ["ComObjCreate", "ComObject"][SubStr(A_AhkVersion, 1, 1)]
  31.         shell := %fn%("WScript.Shell")
  32.         shell.Exec(A_AhkPath " " pipeName)
  33.     } catch {
  34.         return false
  35.     }
  36.     DllCall("Kernel32\ConnectNamedPipe", "Ptr",pipes[1], "Ptr",0)
  37.     DllCall("Kernel32\CloseHandle", "Ptr",pipes[1])
  38.     DllCall("Kernel32\ConnectNamedPipe", "Ptr",pipes[2], "Ptr",0)
  39.     if !(FileOpen(pipes[2], "h", "UTF-8").Write(Script))
  40.         return false
  41.     DllCall("Kernel32\CloseHandle", "Ptr",pipes[2])
  42.     return true
  43. }
  44.  
Add Comment
Please, Sign In to add comment