Gianni Posted June 18, 2017 Posted June 18, 2017 Hi all. I'm playing a bit with the ScriptControl object using as base this example by @genius257. here is a very simple try, ... but it fails. what I'm doing wrong? Local $oSC = ObjCreate("ScriptControl") $oSC.Language = "JScript" $oSC.ExecuteStatement('alert("I am a javascript alert box!");') MsgBox(0,'AutoIt','Pause') Thanks Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
junkew Posted June 18, 2017 Posted June 18, 2017 Maybe set property allowui to true of scriptcontrol interface https://msdn.microsoft.com/en-us/library/aa227400(v=vs.60).aspx FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Gianni Posted June 18, 2017 Author Posted June 18, 2017 Thanks @junkew, AllowUI is now set to True but I got same result Local $oSC = ObjCreate("ScriptControl") $oSC.Language = "JScript" $oSC.AllowUI = True ConsoleWrite("Debug:" & @CRLF & "Language:" & @TAB & $oSC.Language & @CRLF & "AllowUI:" & @TAB & $oSC.AllowUI & @CRLF) $oSC.ExecuteStatement('alert("I am a javascript alert box!");') MsgBox(0,'AutoIt','Pause') Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
junkew Posted June 18, 2017 Posted June 18, 2017 (edited) alert is not a function from javascript its a function from the internet explorer window object. As such you cannot call a msgbox/alert function from JavaScript. Although I remember something as you host the control you can call an AutoIt function within the JScript you run. expandcollapse popupexamplevbs() exampleJS() MsgBox(0,'AutoIt','Pause') func exampleJS() Local $oSC = ObjCreate("MSScriptControl.ScriptControl") $oSC.Language = "JScript" $oSC.AllowUI = True ConsoleWrite("Debug:" & @CRLF & "Language:" & @TAB & $oSC.Language & @CRLF & "AllowUI:" & @TAB & $oSC.AllowUI & @CRLF) ;~ $oSC.ExecuteStatement("alert('I am a javascript alert box!');") ;~ $oSC.Run("alert('I am a javascript alert box!');") $strCode= "alert(" & Chr(39) & "I am a javascript alert box!" & Chr(39) & ");" ConsoleWrite("strCode:" & $strCode & @CRLF ) $oSC.ExecuteStatement("alert('I am a javascript alert box!');") EndFunc func exampleVBs() Local $oSC = ObjCreate("MSScriptControl.ScriptControl") $oSC.Language = "VBScript" $oSC.AllowUI = True ConsoleWrite("Debug:" & @CRLF & "Language:" & @TAB & $oSC.Language & @CRLF & "AllowUI:" & @TAB & $oSC.AllowUI & @CRLF) $strCode= "msgbox " & Chr(34) & "test" & Chr(34) ConsoleWrite("strCode:" & $strCode & @CRLF ) $oSC.ExecuteStatement($strCode) $oSC.Run("alert('I am a javascript alert box!');") EndFunc Not sure what you want to achieve but following roads you could follow 1. mangle JScript with VBScript and AutoIT (with registering AutoIt as com on the fly https://www.autoitscript.com/forum/topic/128627-access-autoit/) 2. Load ChakraCore engine (search ChakraCore in the forums)https://www.autoitscript.com/forum/topic/185996-chakra-native-javascript-runtime-jsrt 3. Embed JScript in a C# module and run it with help of CLR.AU3 examples (not done before I think but then you are less dependent on the MSScriptcontrol. Edited June 19, 2017 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Gianni Posted June 19, 2017 Author Posted June 19, 2017 11 hours ago, junkew said: alert is not a function from javascript its a function from the internet explorer window object. As such you cannot call a msgbox/alert function from JavaScript. ...... ... that make sense.... Thanks @junkew for the suggestions, I will do some tests Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
junkew Posted June 20, 2017 Posted June 20, 2017 Triggered by this thread I will check more on chakra.dll see here the base references of microsoft on embedding Plain dllhttps://github.com/Microsoft/ChakraCore/wiki/Embedding-ChakraCore implemented in AutoIthttps://www.autoitscript.com/forum/topic/185996-chakra-native-javascript-runtime-jsrt/ From .NET (then you should use clr.au3 as can be found in examples)https://github.com/robpaveza/jsrt-dotnet FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
xroot Posted June 21, 2017 Posted June 21, 2017 Hi, Chimp Here is a way to use a msgbox or alert in jscript. Local $oSC = ObjCreate("ScriptControl") $oSC.Language = "JScript" local $jcode = "function alert(iData,iTitle,iFlag,timeout){" & _ "iTitle = iTitle || 'Info';" & _ "iFlag = iFlag || 64;" & _ "timeout = timeout || 0;" & _ "return new ActiveXObject('WScript.Shell').Popup(iData,timeout,iTitle,iFlag);}" $oSC.AddCode($jcode) $oSC.ExecuteStatement("alert('I am a javascript alert box!')") MsgBox(0,'AutoIt','Pause') This runs on IE 11 win 7. Gianni 1
Gianni Posted June 28, 2017 Author Posted June 28, 2017 Hi @xroot, thanks for your "matrioska" script... (WScript within Jscript within AutoIt). Funny example... ThankYou Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now