Página 1 de 1

Como ejecutar Funciones VBScript en AMS

Publicado: 04 May 2011 21:28
por Ceone
AMS: How To Execute A VBScript Function In AMS

In this short tutorial i will show you how to run a VBScript in AMS
VBScript engine has a COM interface to access Microsoft Script Engine
with a ProID called 'ScriptControl'

In AMS we can use LuaCom plugin to access this COM interface and execute our VBScript functions
you can pass a argument to VBScript function and get return value easiliy

there is a limitation , this limitation comes from LuaCom plugin about SAFEARRAY
but this can not inhibit our implementation

basicly we can pass only one argument to our VBScript function , but we can use a delimited string to
avoid this limitation

we will use :
ScriptControl:Run("VBScriptTestFunc","Test Argument 1|Test Argument 2|Test Arguement 3");

instead of
ScriptControl:Run("VBScriptTestFunc","Test Argument 1","Test Argument 2","Test Arguement 3");


This is our test VBScript function

Function VBScriptTestFunc(strInput)

strArgs = Split(strInput,"|",-1,1)
NCount = 1
for each Argument in strArgs

msgbox("Argument "& NCount &" : "& Argument)
NCount = NCount + 1
next

VBScriptTestFunc = "This Is Result Of VBScript"

End Function


like you can see above i used Split(strInput,"|",-1,1) function of VBScript to split input argument
to multiple arguments with a separator i will use in AMS "|" , the separator character can be anything you prefer

This is our caller procedure in AMS :
local ScriptControl = luacom.CreateObject("ScriptControl");
 
if ScriptControl then
 
    ScriptControl:setLanguage("VBScript");
    ScriptControl:setAllowUI(true);
    ScriptControl:setSitehWnd(Application.GetWndHandle());
    ScriptControl:AddCode(strVBSCript);
 
    retval =  ScriptControl:Run("VBScriptTestFunc","Test Argument 1|Test Argument 2|Test Arguement 3");
    Dialog.Message("Notice", retval, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
 
    ScriptControl = nil;
    collectgarbage()
 
end
where VBScriptTestFunc is the name of our VBScript function name
and second argument contains a delimited string to be passed to our VBScritp function
then we will split it in VBScript function

Finally , this is full sample of the tutorial that can be tested by adding it to a buttons On Click event

Note : you should have LuaCom Plugin installed to test/run this code
if not installed then please download it from here and install
strVBSCript = [[
 
  Function VBScriptTestFunc(strInput)
 
    strArgs = Split(strInput,"|",-1,1)
    NCount = 1
    for each Argument in strArgs
 
     msgbox("Argument "& NCount &" : "& Argument)
     NCount = NCount + 1
    next
 
   VBScriptTestFunc = "This Is Result Of VBScript"
 
   End Function
 
   ]]
 
local ScriptControl = luacom.CreateObject("ScriptControl");
 
if ScriptControl then
 
    ScriptControl:setLanguage("VBScript");
    ScriptControl:setAllowUI(true);
    ScriptControl:setSitehWnd(Application.GetWndHandle());
    ScriptControl:AddCode(strVBSCript);
 
    retval =  ScriptControl:Run("VBScriptTestFunc","Test Argument 1|Test Argument 2|Test Arguement 3");
    Dialog.Message("Notice", retval, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
 
    ScriptControl = nil;
    collectgarbage()
 
end

Re: AMS: How To Execute A VBScript Function In AMS

Publicado: 04 May 2011 21:30
por Ceone
este tutorial a sido extraído al completo de

Código: Seleccionar todo

http://www.serkan.ws/?p=175
para mas información dirigiros a la pagina del autor en este caso reteset.

si realmente os gusta puedo traducirlo en un salto.

Re: Como ejecutar Funciones VBScript en AMS

Publicado: 04 May 2011 22:13
por Agotaras123
joder amigo esto esta de PM gracias por este material reteset es un genio.

Publicado: 19 Mar 2014 21:31
por GJUser
¿Cómo ejecuto este script en autoplay?

Set WshShell = CreateObject ("WScript.Shell")

WSHShell.RegWrite "HKLM\SOfTWARE\EA Games\Need for Speed(TM) Rivals\GDFBinary", "C:\Program Files (x86)\EA Games\Need for Speed™ Rivals\GDFBinary_es_ES_64.dll", "REG_SZ"