找回密码
 加入
搜索
楼主: manlty

[AU3基础] autoit脚本程序有没有可能运行从外部读到的代码?

 火.. [复制链接]
发表于 2010-3-28 13:47:21 | 显示全部楼层
本帖最后由 C.L 于 2010-3-28 13:53 编辑

LZ的要求实现起来应该不算麻烦,没有装au3要编译只需很少的文件,我写了个例子(代码在3.3.5.1里测试通过),LZ看看是不是能实现你的要求

我特地将AU3卸了来测试这段代码,在我这里测试通过:

要处理的全代码:
Global $result=0,$testNum = 1,$num = 2
$result = $testNum + $num
MsgBox (0,"","$testNum:"&$testNum&"+$num:2"&$num&"=$result:"&$result)
au3code.txt  (代表从服务器传来的文本,要处理赋值 $num和结果 $result)
Dim $Num = 2,$result = 0
if $cmdline[0] <> "" then;处理命令行
        For $i=1 To $cmdline[0] 
                If $cmdline[$i] = "/testNum" Then
                        $getNum = $cmdline[$i+1]
                        $result = $getNum + $Num
                EndIf
        Next
EndIf
;MsgBox (0,"","处理全局函数$testNum:"&$getNum&"+"&$Num&"="&$result)
_Send("/result "&$result)

Func _send($message);向主程发送执行结果
        $hWnd = WinGetHandle('main')

        $struct = DllStructCreate('wchar var1[1000]')
        DllStructSetData($struct, 1, $message)
        $pStruct = DllStructGetPtr($struct)

        $struct2 = DllStructCreate('dword;dword;ptr')
        DllStructSetData($struct2, 1, 0)
        DllStructSetData($struct2, 2, 1000)
        DllStructSetData($struct2, 3, $pStruct)
        $pStruct2 = DllStructGetPtr($struct2)

        _SendMessage($hWnd, 0x4A, 0, $pStruct2)

Endfunc   ;==>_send

Func _SendMessage($hWnd, $iMsg, $wParam = 0, $lParam = 0, $iReturn = 0, $wParamType = "wparam", $lParamType = "lparam", $sReturnType = "lresult")
        Local $aResult = DllCall("user32.dll", $sReturnType, "SendMessageW", "hwnd", $hWnd, "uint", $iMsg, $wParamType, $wParam, $lParamType, $lParam)
        If @error Then Return SetError(@error, @extended, "")
        If $iReturn >= 0 And $iReturn <= 4 Then Return $aResult[$iReturn]
        Return $aResult
EndFunc   ;==>_SendMessage
test2.au3  (赋值$testNum,得到au3code.txt并编辑成test.exe后运行,接受返回的数值。
Global $result=0,$testNum = 1,$rStr = ""
GUICreate('main')
GUIRegisterMsg(0x4A, '_MsgRec');注册函数来接收
FileInstall ("aut2exe.exe",@TempDir&"\aut2exe.exe")
FileInstall ("AutoItSC.bin",@TempDir&"\AutoItSC.bin")
RunWait(@TempDir&"\aut2exe.exe /in au3code.txt /out test.exe /nopack")
Run ("test.exe /testNum "&$testNum)
While Not $rStr
        Sleep (1000)
WEnd
$sTem = StringSplit ($rStr," ")
If $sTem [1] = "/result" Then $result = $sTem[2]
MsgBox (0,"","收到传来处理结果:$result="&$result)
FileDelete ("test.exe")

Func _MsgRec($hWnd, $iMsg, $iwParam, $ilParam)
        $a = DllStructCreate('dword var1;dword var2;ptr var3', $ilParam)
        $b = DllStructGetData($a, 3)
        $c = DllStructCreate('wchar var1[1000]', $b)
        $getStr = DllStructGetData($c, 1)
        $rStr = $getStr
EndFunc   ;==>_Msg_Rec

评分

参与人数 1金钱 +100 贡献 +25 收起 理由
lynfr8 + 100 + 25 感谢你对论坛的支持,希望以后继续发扬这种 ...

查看全部评分

发表于 2010-3-28 13:51:08 | 显示全部楼层
本帖最后由 C.L 于 2010-3-28 13:58 编辑

编译test2.au3前,将aut2exe.exe和AutoItSC.bin先拷贝到test2.au3目录下再编译即可,客户端不用安装au3,LZ可以测试看看我上面的这段代码是否正常。
我上面的例子只处理了单参数,不过对代码稍为处理,就可以接受多参数的传递的,LZ可以按需扩展。
 楼主| 发表于 2010-3-28 15:02:42 | 显示全部楼层
谢谢高手!
发表于 2010-3-28 15:37:02 | 显示全部楼层
谢谢分享!!
发表于 2010-3-31 13:04:27 | 显示全部楼层
看了上面的讨论,貌似编译成exe只需要很少的文件。
提个问题,#include 怎么办?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-20 07:42 , Processed in 0.069051 second(s), 18 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表